def change_userpassword(): userid = IdentifyUtil.get_user_id() if not userid: return jsonify(Common.falseReturn(None, 'user not find')) params = request.get_json() if not params.get('oldpassword') or not params.get('newpassword'): return jsonify( Common.falseReturn(None, 'newpassword or oldpassword cannot be empty')) user = UserApi.getUserBase(userid) if user['status'] and user['data'].get( 'password') == IdentifyUtil.hash_secret(params.get('oldpassword')): return jsonify( UserApi.updateUserPassword(userid, params.get('newpassword'))) return jsonify(Common.falseReturn(None, 'check old password wrong'))
def change_username(): userid = IdentifyUtil.get_user_id() if not userid: return jsonify(Common.falseReturn(None, 'user not find')) params = request.get_json() if not params.get('username'): return jsonify(Common.falseReturn(None, 'username cannot be empty')) return jsonify(UserApi.updateUserName(userid, params.get('username')))
def post_validPasswordEmail(): params = request.get_json() if 'userid' not in params: return jsonify(Common.falseReturn(None, 'please input userid')) #根据id获取email userinfo = UserApi.getUserInfoByUserid(params.get('userid')) if userinfo['status']: return jsonify( ValidEmail.post_validcode_email(userinfo['data']['email'], "修改密码", 1)) else: return jsonify(Common.falseReturn(None, 'no user'))
def reset_password(): params = request.get_json() if not params.get('emailcode') or not params.get( 'userid') or not params.get('password'): return jsonify( Common.falseReturn( None, 'emailcode and userid and password should not empty')) userbase = UserApi.getUserBase(params.get('userid')) if userbase['status']: userinfo = UserApi.getUserInfoByUserid(userbase['data']['id']) if userinfo['status']: res = ValidEmail.check_validcode_email(userinfo['data']['email'], params.get('emailcode'), 1) if res['status']: return jsonify( UserApi.updateUserPassword(params.get('userid'), params.get('password'))) else: return jsonify(Common.falseReturn(None, 'check code wrong')) else: return jsonify(Common.falseReturn(None, 'get email wrong')) else: return jsonify(Common.falseReturn(None, 'user not exist'))
def register_Auths(): '''注册一个账户,需要提供 post json 信息 {"username":"******","password":"******","realname":???,"idcard":???,"cellphone":???,"email":???,"avatarurl":???}''' params = request.get_json() if not params.get('emailcode') or not params.get('email'): return jsonify(Common.falseReturn(None, 'emailcode if needed')) elif not ValidEmail.check_validcode_email( params.get('email'), params.get('emailcode'), 0)['data']: return jsonify( Common.falseReturn(None, 'please make sure email and code is matched')) if not params.get('username') or not params.get('password'): return jsonify( Common.falseReturn(None, 'username or password cannot be empty')) base = UserApi.registerUserBase(params.get('username'), params.get('password')) if base.get('status'): info = UserApi.registerUserInfo( base.get('data').get('userid'), params.get('realname'), params.get('cellphone'), params.get('idcard'), params.get('email'), params.get('avatarurl')) return jsonify(info) return jsonify(base)
def get_userinfo(): userid = IdentifyUtil.get_user_id() if not userid: return jsonify(Common.falseReturn(None, 'user not find')) return jsonify(UserApi.getUserInfoByUserid(userid))
def get_UserEmail(userid): res = UserApi.getUserInfoByUserid(userid) if res['status']: return jsonify(Common.trueReturn(res['data']['email'], 'ok')) return jsonify(Common.falseReturn(None, 'no user'))
def get_UserIdByName(username): res = UserApi.getUserBaseByName(username) if res['status']: return jsonify(Common.trueReturn(res['data']['id'], 'ok')) else: return jsonify(Common.falseReturn(None, 'no user'))
def get_userAvatar(userid): return jsonify(UserApi.getUserAvatarById(userid))
def get_username(userid): return jsonify(UserApi.getUserNameById(userid))