Exemplo n.º 1
0
    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'})
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
    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)