<commit_before>/**
 * Created by Indexyz on 2017/4/11.
 */
"use strict";
const db = require("mongoose");
const userSchema = require("../../Db/Schema/User");
const userService = require("../../Db/Service/userService");
const Promise = require('bluebird');

module.exports.get = (req, res, next) => {
    let userModel = db.model("users", userSchema);
    userModel.findOne({
        _id: req.session.user._id
    }, (err, doc) => {
        if (err) { next(err); return }
        res.render("member/profile", {
            user: doc
        })
    });
};

module.exports.post = (req, res, next) => {
    let type = req.body.type;

    userService.findById(req.session.user._id, (err, user) => {
        userService.getProfile(user, profile => {
            new Promise((resolve, reject) => {
                switch (type){
                    case "changeUserName": {
                        let username = req.body.username;
                        if (username.length < 3) return reject(new Error("用户名长度太小"));
                        profile.UserName = username;
                        profile.save(err => {
                            if (err) return reject(err);
                            resolve()
                        });
                        break;<commit_msg>[Fix] Profile Page overwrite user value in page<commit_after>/**
 * Created by Indexyz on 2017/4/11.
 */
"use strict";
const db = require("mongoose");
const userSchema = require("../../Db/Schema/User");
const userService = require("../../Db/Service/userService");
const Promise = require('bluebird');

module.exports.get = (req, res, next) => {
    res.render("member/profile");
};

module.exports.post = (req, res, next) => {
    let type = req.body.type;

    userService.findById(req.session.user._id, (err, user) => {
        userService.getProfile(user, profile => {
            new Promise((resolve, reject) => {
                switch (type){
                    case "changeUserName": {
                        let username = req.body.username;
                        if (username.length < 3) return reject(new Error("用户名长度太小"));
                        profile.UserName = username;
                        profile.save(err => {
                            if (err) return reject(err);
                            resolve()
                        });
                        break;
{'fraction_non_alphanumeric': 0.1463002114164905, 'fraction_numerical': 0.006765327695560253, 'mean_word_length': 1.6494960806270997, 'pattern_counts': {'":': 2, '<': 5, '<?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': '3480538', 'n_tokens_mistral': 657, 'n_tokens_neox': 627, 'n_words': 145}