Exemplo n.º 1
0
def register():
    register_key = 'zhucema'
    form = RegistrationForm()
    if form.validate_on_submit():
        if form.registerkey.data != register_key:
            flash(u'注册码不符,请返回重试')
            return redirect(url_for('admin.register'))
        else:
            if form.password.data != form.password2.data:
                flash(u'两次输入密码不一')
                return redirect(url_for('admin.register'))
            else:
                try:
                    user = User(username=form.username.data,
                                password=form.password.data)
                    print(user.password_hash)
                    print(user.username)
                    db.session.add(user)
                    print('done')
                    print('done')
                    flash(u'您已经成功注册')
                    return redirect(url_for('admin.login'))
                except:
                    db.session.rollback()
                    flash(u'用户名已存在')
    return render_template('admin/register.html',
                           form=form,
                           current_time=datetime.utcnow())
Exemplo n.º 2
0
def add_user():
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(username=form.username.data, password=form.password.data, email=form.email.data)
        db.session.add(user)
        db.session.commit()
        flash('Successfully registered %s' % form.username.data)
        return redirect(url_for('.add_user', methods=['GET']))
    return render_template('admin/register.html', form=form, logged_in=current_user.is_authenticated())
Exemplo n.º 3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('admin.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('admin.login'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 4
0
def register():
    if current_user.is_anonymous or current_user.department not in ["admin"]:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    department=form.department.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you have successfully registered a user!')
        return redirect(url_for('admin.user_management'))

    return render_template('admin/register_user.html',
                           title='Register User',
                           form=form)
Exemplo n.º 5
0
    def register_view(self):

        if not Setting.query.filter_by(name=u'show_register_page').first().value == 'true' and len(User.query.all()) > 0:
            return redirect(url_for('.index'))

        form = RegistrationForm()
        if form.validate_on_submit():
            user = User(username=form.username.data, password=form.password.data)

            db.session.add(user)

            flash('User named {} has been created'.format(form.username.data))
            return redirect(url_for('.login_view'))
        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
        self._template_args['desc'] = 'Register an account in order to log in.'
        return super(IndexView, self).index()
Exemplo n.º 6
0
def register():
    """Register user"""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(name=form.name.data,
                    email=form.email.data,
                    role=form.role.data)
        user.set_password(form.password.data)
        db.session.add(user)
        user_id = User.query.filter_by(email=form.email.data).first().id
        checkin = Checkin(user_id=user_id,
                          availability=False,
                          time=datetime.utcnow())
        db.session.add(checkin)
        db.session.commit()
        flash('The new user has been added.')
        return redirect(url_for('admin.users'))
    return render_template('admin/register.html', title='Register', form=form)
Exemplo n.º 7
0
    def register_view(self):

        if not Setting.query.filter_by(
                name=u'show_register_page').first().value == 'true' and len(
                    User.query.all()) > 0:
            return redirect(url_for('.index'))

        form = RegistrationForm()
        if form.validate_on_submit():
            user = User(username=form.username.data,
                        password=form.password.data)

            db.session.add(user)

            flash('User named {} has been created'.format(form.username.data))
            return redirect(url_for('.login_view'))
        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
        self._template_args['desc'] = 'Register an account in order to log in.'
        return super(IndexView, self).index()