def create_user(app, id): new_user = User() psw = b'$2b$12$1Y21IaNbwu357bI4ipaZO.GVvzouAEvnrAy80TGCBRtX5q8OUlIr2' new_user.id = id new_user.name = "test" new_user.email = str(id) + "@mail.com" new_user.password = psw database.addItemSafelyToDB(new_user) return new_user
def register_user(json_data): email = escape(json_data["email"]) name = escape(json_data["name"]) studentid = int(escape(json_data["studentid"])) password = escape(json_data["password"]) repassword = escape(json_data["password_confirmation"]) validated = validate_userdata(email, name, studentid, password, repassword) if validated != '': return Iresponse.create_response({"status": validated}, 200) # Backend check if email/studentid already exists user = User.query.filter_by(email=email).first() if user: return Iresponse.create_response({"status": "Email is taken"}, 200) studentid = json_data["studentid"] user = User.query.filter_by(id=studentid).first() if user: return Iresponse.create_response({"status": "Studentid taken"}, 200) new_user = User() salt = bcrypt.gensalt() hashedpsw = bcrypt.hashpw(password.encode('utf-8'), salt) new_user.password = hashedpsw new_user.id = studentid new_user.name = name new_user.email = email new_user.level = 1 new_user.experience = 1 if not database.addItemSafelyToDB(new_user): return Iresponse.internal_server_error() return Iresponse.create_response({"status": "OK"}, 201)