<commit_before>/**
 * Created by Omnius on 6/18/16.
 */
'use strict';

const generateToken = require(process.cwd() + '/server/helpers/hkdfTokenGenerator').generateToken;

module.exports = () => {

    return (request, reply) => {

        const server = request.server;
        const redis = request.redis;
        const dao = server.methods.dao;
        const userProfileDao = dao.userProfileDao;
        const userCredentialDao = dao.userCredentialDao;
        const credentials = request.auth.credentials;
        const userId = credentials.userId;
        const oldSessionId = credentials.id;

        generateToken(request.info.host + '/hawkSessionToken', null, (newSessionId, newAuthKey, newToken) => {

            userCredentialDao.deleteUserCredential(redis, oldSessionId, (err) => {
                if (err) {
                    server.log(err);
                }
            });

            userCredentialDao.updateUserCredential(redis, newSessionId, {
                hawkSessionToken: newToken,
                userId: userId,
                id: newSessionId,
                key: newAuthKey,
                algorithm: 'sha256'
            }, (err) => {
                if (err) {
                    return reply(err);
                }

                const newCredentials = {
                    hawkSessionToken: newToken,
                    algorithm: 'sha256',
                    userId: userId
                };

                let strCredential = '';

                for (const credential in newCredentials) {
                    if (newCredentials.hasOwnProperty(credential)) {
                        strCredential += (credential + '=' + newCredentials[credential] + ';');
                    }
                }

                userProfileDao.readUserProfile(redis, userId, (err, userProfile) => {
                    if (err) {
                        return reply(err);
                    }

                    return reply(userProfile)
                        .state('Hawk-Session-Token', newCredentials)
                        .header('X-Permitted-Cross-Domain-Policies', 'master-only');
                });
            });
        });
    };
};<commit_msg>Remove unused codes<commit_after>/**
 * Created by Omnius on 6/18/16.
 */
'use strict';

const generateToken = require(process.cwd() + '/server/helpers/hkdfTokenGenerator').generateToken;

module.exports = () => {

    return (request, reply) => {

        const server = request.server;
        const redis = request.redis;
        const dao = server.methods.dao;
        const userProfileDao = dao.userProfileDao;
        const userCredentialDao = dao.userCredentialDao;
        const credentials = request.auth.credentials;
        const userId = credentials.userId;
        const oldSessionId = credentials.id;

        generateToken(request.info.host + '/hawkSessionToken', null, (newSessionId, newAuthKey, newToken) => {

            userCredentialDao.deleteUserCredential(redis, oldSessionId, (err) => {
                if (err) {
                    server.log(err);
                }
            });

            userCredentialDao.updateUserCredential(redis, newSessionId, {
                hawkSessionToken: newToken,
                userId: userId,
                id: newSessionId,
                key: newAuthKey,
                algorithm: 'sha256'
            }, (err) => {
                if (err) {
                    return reply(err);
                }

                const newCredentials = {
                    hawkSessionToken: <PASSWORD>Token,
                    algorithm: 'sha256',
                    userId: userId
                };

                userProfileDao.readUserProfile(redis, userId, (err, userProfile) => {
                    if (err) {
                        return reply(err);
                    }

                    return reply(userProfile)
                        .state('Hawk-Session-Token', newCredentials)
                        .header('X-Permitted-Cross-Domain-Policies', 'master-only');
                });
            });
        });
    };
};
{'fraction_non_alphanumeric': 0.10499390986601705, 'fraction_numerical': 0.00535931790499391, 'mean_word_length': 1.4382422802850356, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, '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': '361559', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1040, 'n_words': 196}