def register_view(self): if not current_user.is_authenticated: return redirect(url_for('.login_view')) form = RegistrationForm(request.form) if helpers.validate_form_on_submit(form): user = UserModel() form.populate_obj(user) # we hash the users password to avoid saving it as plaintext in the db, # remove to use plain text: user.password = generate_password_hash(form.password.data) user.save() login_user(user) return redirect(url_for('.index')) link = '<p>Already have an account? <a href="' + url_for( '.login_view') + '">Click here to log in.</a></p>' self._template_args['form'] = form self._template_args['link'] = link return self.render('auth.html')
def add(self): form = RegistrationForm(request.form) if helpers.validate_form_on_submit(form): user = UserModel() form.populate_obj(user) # we hash the users password to avoid saving it as plaintext in the db, # remove to use plain text: user.password = generate_password_hash(form.password.data) user.t = int(time.time()) user.ut = int(time.time()) user.save() return '1' else: errors = {} for f in form: if f.errors: errors[f.name] = f.errors[0] return json.dumps(errors) return "0"