def post(self, **kwargs): args = register_parser.parse_args() username, password = args["username"], args["password"] salt = app.config.get("SALT", b"") password = bcrypt.hashpw(password.encode('utf8'), bytes(salt.encode())) default_active = not ENABLE_EMAIL_ACTIVE try: user = User(username, password, active=default_active) user_id = user.save() user = user.get_by_id(user_id) data = { "username": user.username, "apikey": str(user.id), "isActivated": user.active, "balance": user.balance, "success": True } return data, 200 except Exception as exc: logger.error("exc %s", exc) data = { "success": False, "error": "register failed" } return data, 400
def post(self, user_id): args = user_password_parser.parse_args() origin_password, new_password = \ args["old_password"], args["new_password"] op_log_handler = OperatorLogHandler() opName = 'ChangePassword' opObject = "User" opDetails = {} cur_time = datetime.datetime.utcnow() user_obj = User() user = user_obj.get_by_id(user_id) operator = user.username if not user: error_msg = "No such User" op_log_handler.record_operating_log(opDate=cur_time, opName=opName, opObject=opObject, resCode=400, operator=operator, errorMsg=error_msg, opDetails=opDetails) return {"error": "No such User", "success": False}, 400 salt = app.config.get("SALT", b"") password = bcrypt.hashpw(origin_password.encode('utf8'), bytes(salt.encode())) if not password.decode() == user.dbUser.password: error_msg = "Invalid origin password" op_log_handler.record_operating_log(opDate=cur_time, opName=opName, opObject=opObject, resCode=400, operator=operator, errorMsg=error_msg, opDetails=opDetails) return {"error": "Invalid origin password", "success": False}, 400 new_password = bcrypt.hashpw(new_password.encode('utf8'), bytes(salt.encode())) user.update_password(new_password.decode()) data = {"success": True} op_log_handler.record_operating_log(opDate=cur_time, opName=opName, opObject=opObject, resCode=200, operator=operator, opDetails=opDetails) return data, 200
def get(self, user_id): user_obj = User() user = user_obj.get_by_id(user_id) if not user: return {"error": "No such User", "success": False}, 400 data = { "username": user.username, "apikey": str(user.id), "isActivated": user.active, "balance": user.balance, "success": True } return data, 200
def post(self, user_id): args = user_password_parser.parse_args() new_password = args["new_password"] user_obj = User() user = user_obj.get_by_id(user_id) if not user: return {"error": "No such User", "success": False}, 400 salt = app.config.get("SALT", b"") new_password = bcrypt.hashpw(new_password.encode('utf8'), bytes(salt.encode())) user.update_password(new_password.decode()) data = {"success": True} return data, 200
def put(self, user_id): """ Update user profile :param user_id: user id of User to update profile :return: api response, status code """ args = update_profile_parser.parse_args() name, email_addr = args["name"], args["email"] bio, url = args["bio"], args["url"] location = args["location"] user_obj = User() user = user_obj.get_by_id(user_id) if not user: return {"error": "No such User", "success": False}, 400 else: user.update_profile(name=name, email=email_addr, bio=bio, url=url, location=location) return {"success": True}, 200
def post(self, user_id): args = user_password_parser.parse_args() new_password = args["new_password"] user_obj = User() user = user_obj.get_by_id(user_id) if not user: return {"error": "No such User", "success": False}, 400 salt = app.config.get("SALT", b"") new_password = bcrypt.hashpw(new_password.encode('utf8'), bytes(salt.encode())) user.update_password(new_password.decode()) data = { "success": True } return data, 200
def post(self, **kwargs): args = register_parser.parse_args() username, password = args["username"], args["password"] salt = app.config.get("SALT", b"") password = bcrypt.hashpw(password.encode('utf8'), bytes(salt.encode())) try: user = User(username, password) user_id = user.save() user = user.get_by_id(user_id) data = { "username": user.username, "apikey": str(user.id), "isActivated": user.active, "balance": user.balance, "success": True } return data, 200 except Exception as exc: logger.error("exc %s", exc) data = {"success": False, "error": "register failed"} return data, 400
def post(self): args = user_password_parser.parse_args() origin_password, new_password, new_password2 = \ args["origin_password"], args["new_password"], args["new_password2"] if new_password != new_password2: return {'stat': -1, 'msg': '两次密码输入不一致'} user_obj = User() user = user_obj.get_by_id(current_identity.id) if not user: return {"msg": "用户不存在", "stat": -1}, 400 if user.check_password(user.dbUser.password, origin_password): return {"msg": "原始密码错误", "stat": -1}, 400 password = user.set_password(new_password) user.update_password(password) data = { 'id': user.id, "stat": -1, 'msg': '密码修改成功' } return data, 200
def get(self, user_id): """ Get user profile information :param user_id: user id of User to query :return: profile data, status code """ user_obj = User() user = user_obj.get_by_id(user_id) if not user: return {"error": "No such User", "success": False}, 400 data = { "result": { "username": user.username, "name": user.profile.name if user.profile else "", "email": user.profile.email if user.profile else "", "bio": user.profile.bio if user.profile else "", "url": user.profile.url if user.profile else "", "location": user.profile.location if user.profile else "", }, "success": True } return data, 200