Ejemplo n.º 1
0
 def register_user(self):
     if current_user.is_authenticated():
         raise RequestException("you're already logged in")
     params = self._get_json_func_params(
         requiredParams=["email", "password", "password_confirm", "recaptcha_challenge_field", 
             "recaptcha_response_field", "initial_workout_plan_uid", "initial_rest_plan_uid"])
     form_class = app.extensions['security'].confirm_register_form
     form_data = MultiDict(params)
     form = form_class(form_data)
     if form.validate_on_submit():
         user = flask_security_register_user(**form.to_dict())
         user.create_profile()
         user.create_default_meal_plans(
             initial_workout_plan_uid=params["initial_workout_plan_uid"], 
             initial_rest_plan_uid=params["initial_rest_plan_uid"])
         form.user = user
         db.session.commit()
         flask_security_login_user(user)
     has_errors = len(form.errors) > 0
     #this doesnt currently fit well with simpleapi's success variable and can definitely be improved
     if has_errors:
         response = {
             'code': 400,
             'errors': form.errors
         }
     else:
         response = {
             'code': 200,
             'app_context': AppContext.make_json_encodable_context()
         }
     return response
Ejemplo n.º 2
0
 def login_user(self):
     if current_user.is_authenticated():
         raise RequestException("you're already logged in")
     params = self._get_json_func_params(
         requiredParams=["email", "password"])
     form_class = app.extensions['security'].login_form
     form = form_class(MultiDict(params))
     if form.validate_on_submit():
         flask_security_login_user(form.user)
         db.session.commit()
     has_errors = len(form.errors) > 0
     #this doesnt currently fit well with simpleapi's success variable and can definitely be improved
     if has_errors:
         response = {
             'code': 400,
             'errors': form.errors
         }
     else:
         response = {
             'code': 200,
             'app_context': AppContext.make_json_encodable_context()
         }
     return response