def post(self): self.is_valid_json(raise_exception=True) form = RegistrationForm(data=self.get_json_data()) if not form.validate(): self.write_error(HTTPStatus.BAD_REQUEST, message=form.errors) return None username = form.data.get('username') user = yield self.settings['db'].users.find_one({'username': username}) if user is not None: self.write_error(HTTPStatus.BAD_REQUEST, message=self.default_errors['not_unique'] % username) return None user_info = form.data hashed_password = yield utils.auth.make_password(user_info['password']) user_info.update({ 'password': hashed_password, 'joined_at': datetime.datetime.utcnow() }) yield self.settings['db'].users.insert_one(user_info) user = yield self.settings['db'].users.find_one(user_info) yield self.settings['db'].tokens.update( { 'key': self.request.auth_token['key'], }, {'$set': { 'user': user['_id'] }}) self.write({'detail': 'You successfully registered'})
def register() -> Response: form = RegistrationForm() if form.validate_on_submit(): username = form.data['username'] password = form.data['password'] mail = form.data['mail'] hashed_pswd = pbkdf2_sha256.hash(password) user = Users(username=username, mail=mail, password=hashed_pswd, confirmed=False) db.session.add(user) db.session.commit() token = SendingMails(app, mail).generate_confirmation_token(user.mail) confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('users/activate.html', confirm_url=confirm_url) subject = "Please confirm your email" SendingMails(app, mail).send_email(user.mail, subject, html) flash('A confirmation email has been sent via email. :)', 'success') return redirect(url_for('unconfirmed')) return render_template('users/register.html', form=form)
def registration(): form = RegistrationForm() if request.method == 'POST': if form.validate(): new_user = OrmUser(user_email=form.user_email.data, user_password=form.user_confirm_password.data) db.session.add(new_user) db.session.commit() newSession(new_user.user_email, new_user.user_password) return render_template('success.html') else: return render_template('registration.html', form=form) return render_template('registration.html', form=form)
def registration(): form = RegistrationForm() if request.method == 'POST': if form.validate(): try: new_user = User(user_name=form.user_name.data, user_password=form.user_confirm_password.data) db.session.add(new_user) db.session.commit() newSession(new_user.user_name, new_user.user_password) except: form.user_name.errors = ['user exist'] return render_template('registration.html', form=form) else: return render_template('index.html', form=form) return render_template('registration.html', form=form)
def post(self): """ Create new user and redirect user to home page If error, display form with errors details """ form = RegistrationForm(self.request.POST) if form.validate(): user_key = User.new_user(form.email.data, form.username.data, form.password.data) if user_key: cookie = create_cookie("uid", user_key) self.response.headers.add_header("Set-Cookie", cookie) self.redirect_to("home") else: self.abort(500) self.render_signup(form)
def add_course(): form = RegistrationForm(csrf_enabled=False) if form.validate_on_submit(): id = db_functions.insert_classes( form.lesson.data, form.lecturer.data, form.studio.data, form.day.data, form.time_from.data, form.time_to.data, form.age_group.data, form.level.data, form.course_type.data, form.address.data, form.address_city.data, form.link.data, form.email_address.data, ) print("Inserted row as ID " + str(id)) return redirect(url_for("seznam")) return render_template('registrace.html', form=form)
def get(self): """ Display the form to register """ form = RegistrationForm() self.render_signup(form)