<commit_before>var inherits = require('util').inherits,
    GenericRegistrationService = require('./GenericRegistrationService'),
    UserDevice = require('../models/userdevice');

function AppleRegistrationService () {
    GenericRegistrationService.apply(this, arguments);
}

inherits(AppleRegistrationService, GenericRegistrationService);

/**
 * registers the apple device, which is request by this request, to the logged in user, or upgrades it,
 * if it is already registered.
 *
 * @param req
 * @param res
 */
AppleRegistrationService.prototype.register = function (req, res) {
    var self = this;

    if (!this.validateRequest(req, res)) {
        return;
    }

    UserDevice.findOne({
        owner: req.user.id,
        deviceType: 'ios',
        deviceId: deviceId
    }, function (error, userDevice) {
        if (error) {
            self.getLogger().warn('openHAB-cloud: Error looking up device: ' + error);
            res.send(500, 'Internal server error');
            return;
        }
        if (userDevice) {
            // If found, update device token and save
            self.logger.info('openHAB-cloud: Found iOS device for user ' + req.user.username + ', updating');
            userDevice.iosDeviceToken = <PASSWORD>();
            userDevice.lastUpdate = new Date();
            userDevice.save(function (error) {
                if (error) {
                    self.getLogger().error('openHAB-cloud: Error saving user device: ' + error);
                }
            });
            res.send(200, 'Updated');
        } else {
            // If not found, add new device registration
            self.getLogger().info('openHAB-cloud: Registering new iOS device for user ' + req.user.username);
            userDevice = new UserDevice({
                owner: req.user.id,
                deviceType: 'ios',
                deviceId: deviceId,
                iosDeviceToken: <PASSWORD>(),
                deviceModel: self.getDeviceModel(),
                lastUpdate: new Date(),
                registered: new Date()
            });
            userDevice.save(function (error) {<commit_msg>Fix AppleRegistrationService to use context provided interfaces (#155)<commit_after>var inherits = require('util').inherits,
    GenericRegistrationService = require('./GenericRegistrationService'),
    UserDevice = require('../models/userdevice');

function AppleRegistrationService () {
    GenericRegistrationService.apply(this, arguments);
}

inherits(AppleRegistrationService, GenericRegistrationService);

/**
 * registers the apple device, which is request by this request, to the logged in user, or upgrades it,
 * if it is already registered.
 *
 * @param req
 * @param res
 */
AppleRegistrationService.prototype.register = function (req, res) {
    var self = this;

    if (!this.validateRequest(req, res)) {
        return;
    }

    UserDevice.findOne({
        owner: req.user.id,
        deviceType: 'ios',
        deviceId: this.getDeviceId()
    }, function (error, userDevice) {
        if (error) {
            self.getLogger().warn('openHAB-cloud: Error looking up device: ' + error);
            res.send(500, 'Internal server error');
            return;
        }
        if (userDevice) {
            // If found, update device token and save
            self.getLogger().info('openHAB-cloud: Found iOS device for user ' + req.user.username + ', updating');
            userDevice.iosDeviceToken = <PASSWORD>.getRegistrationId();
            userDevice.lastUpdate = new Date();
            userDevice.save(function (error) {
                if (error) {
                    self.getLogger().error('openHAB-cloud: Error saving user device: ' + error);
                }
            });
            res.send(200, 'Updated');
        } else {
            // If not found, add new device registration
            self.getLogger().info('openHAB-cloud: Registering new iOS device for user ' + req.user.username);
            userDevice = new UserDevice({
                owner: req.user.id,
                deviceType: 'ios',
                deviceId: self.getDeviceId(),
                iosDeviceToken: self.getRegistrationId(),
                deviceModel: self.getDeviceModel(),
                lastUpdate: new Date(),
                registered: new Date()
            });
            userDevice.save(function (error) {
{'fraction_non_alphanumeric': 0.11413540713632205, 'fraction_numerical': 0.0034309240622140895, 'mean_word_length': 2.155122655122655, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4225268', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1089, 'n_words': 297}