def login(): """用户登录 (GET|POST) :uri: /users/login :param name: 用户名 :param password: 密码 :param type: 登陆类型(name, phone,) :returns: {'user': object, 'ut': string} """ params = request.values login_type = params.get('type', 'name') name = params.get("name", None) password = params.get("password", None) if name is None or password is None or login_type not in ['name', 'phone']: return error.InvalidArguments user = User.login(name, password, login_type=login_type) if not user: return error.LoginFailed # 初始化用户任务 UserTask.create_and_init_user_tasks(str(user._id)) token = User.gen_token(str(user._id)) return {'user': user.format(), 'ut': token}
def change_pwd(uid): """修改密码 (GET|POST&LOGIN) :uri: /users/<string:uid>/change-password :param old_pwd: 旧密码 :param new_pwd: 新密码 :returns: {} """ user = request.authed_user params = request.values old_pwd = params.get('old_pwd', None) new_pwd = params.get('new_pwd', None) user = User.login(user.name, old_pwd) if not user: return error.AuthFailed('原密码不正确') invalid_error = User.invalid_password(new_pwd) if invalid_error: return invalid_error User.change_pwd(user, new_pwd) return {}