def put(self): args = request.args.to_dict() updates = request.json print(updates) user = None if 'id' in args: user = User.update(args['id'], updates) else: user = User.update(str(current_user.id), updates) if not user: return {"message": "User not found id={}".format(args['id'])}, 404 return json.loads(user.to_json())
def get(self): args = request.args.to_dict() _id = get_field("id", args) code = int(get_field("code", args)) user = User.find_user_by_id(_id) if not user: return jsonify( {'message': 'Account already confirmed. Please login.'}) if user.confirmed: return jsonify( {'message': 'Account already confirmed. Please login.'}) updates = { 'confirmed': True, 'confirmed_on': datetime.datetime.utcnow() } if code == user.code: User.update(str(user.id), updates) return json.loads(user.to_json()) return jsonify({'message': 'Not valid code'}), 400
def get(self): args = request.args.to_dict() code = get_field("code", args) username = get_field("username", args) pwd = get_field("pwd", args) user = User.find_user_by_username(username) if code != None and pwd != None: code = int(code) print(user.code, code) if not code == user.code: return {'message': 'Code isn\'t correct'}, 401 user.refresh_token() user = User.update(str(user.id), {'password': pwd}) login_user(user) return {'token': user.token}, 200 elif code != None: code = int(code) if code != user.code: return {'message': 'Code isn\'t correct'}, 401 return {'message': 'Code is correct'}, 200 return {'message': 'Some server errors, cheers :)'}, 500