{"size": 939, "ext": "js", "max_stars_repo_path": "apps/admin/actions/user.js", "max_stars_repo_name": "evandu/jianjian", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "apps/admin/actions/user.js", "max_issues_repo_name": "evandu/jianjian", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "apps/admin/actions/user.js", "max_forks_repo_name": "evandu/jianjian", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.4545454545, "max_line_length": 103, "alphanum_fraction": 0.5910543131}
'use strict';

const UserDao       = require('../../../models/user.js');
const bcrypt        = require('co-bcrypt');    // bcrypt library

const user = module.exports = {};

user.edit =function*(){
    const context = {
        module: {
            name:    '系统管理',
            subName: '编辑账号',
        },
    };
    const res = yield UserDao.get(this.params.id || this.passport.user.UserId );
    yield this.render('templates/user/edit',{
        module: context.module,
        data:   res,
    });
};


user.processEdit = function*(){
    if(!this.request.body.Password || this.request.body.Password == ''){
        delete this.request.body.Password;
    }else{
        const salt = yield bcrypt.genSalt(10)
        this.request.body.Password  = yield bcrypt.hash(this.request.body.Password,salt);
    }
    this.flash =  yield UserDao.update(this.params.id || this.passport.user.UserId, this.request.body);
    this.redirect('/');
};
