def create_user(): body = json.loads(request.data) correct_user = Users.query.filter_by(username=body.get('username')).first() if correct_user == None: user = Users(email=body.get('email'), username=body.get('username'), password=body.get('password')) db.session.add(user) db.session.commit() return json.dumps({'success': True, 'data': user.serialize()}), 201 else: correct_user2 = Users.query.filter_by( password=body.get('password')).first() if correct_user == correct_user2 and correct_user != None: return json.dumps({ 'success': True, 'data': correct_user.serialize() }), 200 return json.dumps({ 'success': False, 'error': 'Password is incorrect. Try again.' }), 404 return json.dumps({ 'success': False, 'error': 'Username or Password is not correct. Try again.' }), 404
def createUser(): postBody = json.loads(request.data) name = postBody.get('name') password = postBody.get('password') user = Users(name=name, password=password) db.session.add(user) db.session.commit() return json.dumps({'success': True, 'data': user.serialize()}), 201
def create_user(): if Signs.query.all() == []: load_scopes() body = json.loads(request.data) name = body.get("name") sign_name = body.get("sign") sign_num = 0 for key in scope_dict: if scope_dict.get(key) == sign_name: sign_num = key sign = Signs.query.filter_by(sign=sign_num).first() if name is None or sign is None: return failure_response("Missing field!", 400) new_user = Users(name=name, sign_id=sign.serialize().get("id")) db.session.add(new_user) db.session.commit() return success_response(new_user.serialize(), 201)