示例#1
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', type=str, required=True,
                            help='The desired username. Should be unique '
                                 'within the system')
        parser.add_argument('password', type=str, required=True,
                            help='Password, please pick something secure')
        parser.add_argument('fullname', type=str, required=True,
                            help='Your full name')
        parser.add_argument('email', type=str, required=True,
                            help='Your email address')
        args = parser.parse_args()

        try:
            new_user = User.create(args['username'],
                                   args['fullname'],
                                   args['email'],
                                   args['password'])
            return {
                        'username': new_user.username,
                        'fullname': new_user.fullname,
                        'email': new_user.email
                   }, 201
        except DuplicateUserError:
            abort(409, message='A user with this username already exists')
示例#2
0
def sign_up_user():
    current_user = check_if_user_signed_in(request.cookies, db_sess)
    if current_user:
        return redirect("/users/game")

    res = User.create(request.form["login"], request.form["password"], db_sess)
    user = res[0]
    user_session = res[1]

    http_res = make_response(redirect("/"))
    http_res.set_cookie("user_secret",
                        str(user_session.value),
                        max_age=60 * 60 * 24 * 365 * 2)
    return http_res