Exemple #1
0
def register():
    if app.config['REGISTRATION_ENABLED'] and app.config['AUTH_TYPE'] == 'plain':
        reg_form = RegistrationForm()
        login_form = LoginForm()

        if reg_form.validate_on_submit():
            user = UserPlain(username=reg_form.username.data,
                             password=reg_form.password.data,
                             email=reg_form.email.data)
            # save user to db
            user_id, save_error = user.save()
            if user_id:
                # try to login
                if login_user(user):
                    flash(gettext('Logged in successfully.'), 'success')
                    return redirect(url_for('search'))
                else:
                    flash(gettext('Unable to log you in.'), 'warning')
                    return redirect(url_for('home'))
            else:
                flash(save_error, 'warning')
                return redirect(url_for('register'))
        else:
            flash_form_errors(reg_form)
            return render_template('register.html', reg_form=reg_form, login_form=login_form)
    else:
        return redirect(url_for('home'))
def registration():
    form = RegistrationForm()
    if form.validate_on_submit():
        if form.password.data != form.repeat_password.data:
            flash('passwords are not equal')
            return render_template('registration.html',
                                   title='Sign Up',
                                   form=form)
        user = User.query.filter_by(login=form.login.data).first()
        if user is not None:
            flash('user with this login already exists')
            return render_template('registration.html',
                                   title='Sign Up',
                                   form=form)
        if User.query.filter_by(email=form.email.data).first() is not None:
            flash('user with this e-mail already exists')
            return render_template('registration.html',
                                   title='Sign Up',
                                   form=form)

        g = send_email_confirmation(form.login.data, form.email.data)

        guid = GuidForRegistration(guid=str(g), login=form.login.data,
                                   password=md5(form.password.data.encode()).hexdigest(),
                                   email=form.email.data)
        db.session.add(guid)
        db.session.commit()
        flash('registration was successful. please wait for confirmation by mail')

        return redirect(url_for('index'))
    return render_template('registration.html',
                           title='Sign Up',
                           form=form)
Exemple #3
0
 def post(self):
     if g.user is not None and g.user.is_authenticated:
         return redirect(url_for('IndexView:get_0'))
     form = RegistrationForm(request.form)
     if form.validate_on_submit():
         form.save()
         login_user(form.user, True)
         return redirect(url_for('IndexView:get_0'))
     return render_template('registration.html', title='Sign In', form=form)
Exemple #4
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User()
        form.populate_obj(user)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('/index'))
    return render_template('register.html', title = 'Register', form = form)
Exemple #5
0
 def update(self, id_):
     user = User.get_or_abort(id_)
     if not user == current_user:
         pass
     form = RegistrationForm(obj=user)
     if form.validate_on_submit():
         user.update(**form.data)
         self.flash_success('Changes have been saved!')
         return self.redirect('User:get', id_=user.id)
     return self.render('user/edit.html', user=user, form=form)
Exemple #6
0
 def create(self):
     if current_user.is_authenticated():
         return self.redirect('UserEvents:index')
     form = RegistrationForm()
     if form.validate_on_submit():
         user = User.create(**form.data)
         login_user(user=user, remember=True)
         self.flash_success('Thank you for registering!')
         return self.redirect('UserEvents:index')
     return self.render('user/new.html', form=form)
Exemple #7
0
def register():
    Form = RegistrationForm()
    if Form.validate_on_submit():
        user = User(email=Form.email.data, username=Form.username.data,
                    password=Form.password.data, nickname=Form.nickname.data)
        db.session.add(user)
        db.session.commit()
        flash('You can login Now !')
        return redirect(url_for('index'))
    return render_template('register.html', form=Form)
Exemple #8
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(form.username.data, form.email.data,
                    form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(u'感谢您的注册')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Exemple #9
0
def add_monkey():
    form = RegistrationForm()
    if form.validate_on_submit():
        monkey = Monkey()
        form.populate_obj(monkey)
        monkey.add_friend(monkey)
        db.session.add(monkey)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('addMonkey.html', title='Add Monkey', form=form)
Exemple #10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('login'))
    return render_template('register.html', title='Register', form=form)
def signup():
    """Render website's sign up page."""
    form = RegistrationForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            email       = request.form['email'].strip()
            password    = request.form['password'].strip()
            
            user = User(email=email, password=password)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('signin'))
    return render_template('signup.html', form=form)
Exemple #12
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    context = {'form': form}
    if form.validate_on_submit():
        u = User(name=form.name.data,
                 email=form.email.data,
                 password=form.password.data)
        db.session.add(u)
        db.session.commit()
        flash('User has been registered', 'alert alert-info')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", **context)
Exemple #13
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    prefix=form.prefix.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now registered!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #14
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('address_book'))
    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()
        login_user(user, remember=False)
        return redirect(url_for('address_book'))
    return render_template('registration_form.html',
                           title='Register',
                           form=form)
Exemple #15
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    #After validating the form...
    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()
        fmsg = 'Greetings '+ str(user.username) + '!! Welcome to the VyasNet!'
        flash(fmsg)
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #16
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('Теперь вы готовы идти на занятия!')
        return redirect(url_for('login'))
    return render_template('register.html',
                           title='Записаться в журнал',
                           form=form)
Exemple #17
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        return redirect(url_for('main.login'))

    return render_template('register.html', title='Register', form=form)
Exemple #18
0
def sign_up():
    r_form = RegistrationForm(request.form)
    user_details = get_user_details()

    if r_form.validate_on_submit():
        # user_details = DirectoryAndFileReader.get_user_details()
        user = User(username=r_form.username.data, email=r_form.email.data, eppn=user_details[0], role_id=2)
        db.session.add(user)
        db.session.commit()
        DirectoryAndFileWriter.create_user_directory(get_user_id(user_details[0]))
        # send_email(user.email, 'Confirm Your Account', 'mail/confirm', user=user, token=token)
        return redirect(url_for('userManagement.unconfirmed'))

    return render_template('sign_up.html', r_form=r_form, username=user_details[1], email=user_details[2])
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(name=form.name.data,
                    cpf=form.cpf.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #20
0
def register():
    """用户注册"""
    if current_user.is_authenticated:  # 如果用户已经是登录状态,返回主页
        return redirect(url_for('index'))

    form = RegistrationForm()
    if form.validate_on_submit():
        new_user = User(username=form.username.data, email=form.email.data)
        new_user.set_password(form.password.data)
        db.session.add(new_user)  # 向数据库添加用户
        db.session.commit()
        flash('注册成功!')
        return redirect(url_for('login'))
    return render_template('register.html', title='注册页面', form=form)
Exemple #21
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
        #make sure isn't already logged in
    form = RegistrationForm()
    if form.validate_on_submit():
        #creating a new user
        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('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #22
0
def register():

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data)

        user = Users(first_name=form.first_name.data,
                     last_name=form.last_name.data,
                     email=form.email.data,
                     password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('post'))
    return render_template('register.html', title="Register", form=form)
Exemple #23
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User()
        user.username = form.username.data.lower()
        user.email = form.email.data.lower()
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Поздравляем с успешной регистрацией!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #24
0
def register():
    """Uses the database file to store credential information. Username, password, confirm password and submit fields
    are used. Once registered, the information is saved locally """
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    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('User successfully registered')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #25
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('Félicitation, vous êtes maintenant un utilisateur enregistré !')
        return redirect(url_for('login'))

    return render_template('register.html', form=form)
Exemple #26
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()

    if form.validate_on_submit():
        user1 = User(username=form.username.data)
        user1.set_password(form.password.data)
        db.session.add(user1)
        db.session.commit()
        flash('Congratulation you have been registered')
        redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #27
0
def register():
    # 确定用户是否登录
    if current_user.is_authenticated:
        return redirect(url_for('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('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #28
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data,
                    last_name=form.last_name.data, first_name=form.first_name.data,
                    city_id=form.city.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Поздравляем, вы зарегистрированы!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #29
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('logout'))
    registerForm = RegistrationForm()
    loginForm = LoginForm()
    if registerForm.validate_on_submit():
        u = User(username=registerForm.username.data,
                 email=registerForm.email.data)
        u.set_password(registerForm.password.data)
        db.session.add(u)
        db.session.commit()
        flash('congratulations! You are now registered!')
        return redirect(url_for('register'))
    return render_template('forms.html', form1=registerForm, df=df)
Exemple #30
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    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(
            'You have successfully been registered. Please log in to access your account'
        )
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #31
0
def login():
    loginForm = LoginForm()
    registrForm = RegistrationForm()
    submit_mode = registrForm.submit.raw_data and registrForm.submit.raw_data[0]
    if submit_mode == 'Войти':
        if loginForm.validate_on_submit():
            username = loginForm.username.data
            if '@' in username:
                user = User.query.filter_by(mail=username).first()
            else:
                user = User.query.filter_by(phone=username).first()
            login_user(user)
            flash('Login requested for user {}, remember_me={}'.format(
                loginForm.username.data, loginForm.remember_me.data))

            next = request.args.get('next')
            print(next)
            return redirect(next or url_for('index'))

    elif submit_mode == 'Регистрация':
        if registrForm.validate_on_submit():
            userData = {
                'name': registrForm.name.data,
                'pname': registrForm.pname.data,
                'sname': registrForm.sname.data,
                'activity': registrForm.activity.data
            }
            uname = registrForm.username.data
            user = None
            if '@' in uname:
                userData["mail"] = uname
            else:
                userData["phone"] = uname

            user = User()
            user.init_of_dict(userData)
            user.image = '/avatar.svg'

            user.set_password(registrForm.password.data)
            db.session.add(user)
            db.session.commit()
            next = request.args.get('next')
            login_user(user)
            return redirect(next or url_for('index'))

    return render_template('login.html',
                           title='Вход',
                           loginForm=loginForm,
                           registrForm=registrForm)
Exemple #32
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('You are now registered!')
        return redirect(url_for('login'))
    return render_template('register.html',
                           appname='The Jam',
                           app_page='Register',
                           form=form)
Exemple #33
0
def setup():
    users = User.query.all()
    if users:
        abort(404)
    form = RegistrationForm()
    if form.validate_on_submit():
        if form.password.data != form.password_confirm.data:
            flash('Passwords do not match')
            return redirect(url_for('setup'))
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('setup.html', form=form)
Exemple #34
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    username=form.username.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("Registration successful for user {}".format(
            form.username.data))
        flash("Login using your credentials below")
        return redirect(url_for('login'))
    return render_template("register.html", title="Register", form=form)
Exemple #35
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created', 'primary')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #36
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form=RegistrationForm()
    
    if form.validate_on_submit():
           
           
           user=User(username=form.username.data,email=form.email.data,password=form.password.data)
           db.session.add(user)
           db.session.commit()
           flash(f'Account created.You are now a user', 'success')
           return redirect(url_for('login'))
           
    return render_template('login/register.html',form=form, title='Register')
Exemple #37
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        if form.username.data == 'admin':
            user = User(login=form.username.data, is_moderator=True)
        else:
            user = User(login=form.username.data, is_moderator=False)
        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('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #38
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(f_name=form.f_name.data,
                    l_name=form.l_name.data,
                    username=form.username.data,
                    email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("Congratulations! You're registered.")
        login_user(user)
    return render_template('login.html', title="Register", form=form)
Exemple #39
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
            email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        
        token = user.generate_confirmation_token()
        send_confirmation_email(user)
        flash('确认邮件已发送至您的邮箱,请点击其中链接完成注册')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', title='注册', form=form)
Exemple #40
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Аккаунт создан. Добро пожаловать', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #41
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('Configurates, you are now a registred user!')
        return redirect(url_for('login'))
    '''Логика, выполняемая внутри условия if validate_on_submit(), создает нового пользователя с именем, 
    электронной почтой и паролем, записывает их в базу данных и затем перенаправляет запрос на вход, чтобы 
    пользователь мог войти в систему.'''
    return render_template('register.html', title='Register', form=form)
Exemple #42
0
def register():
    # if current_user.is_authenticated:
    # return redirect(url_for('index'))
    # prevent non-admins from accessing the page
    if not current_user.is_admin:
        abort(403)
    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('New registered user: %s' % form.username.data)
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #43
0
def signup():
    error = None
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(
            username=form.username.data, 
            email=form.email.data,
            avatar=form.avatar.data,
            password=form.password.data
            )
        db.session.add(user)
        db.session.commit()
        referer = request.headers.get("Referer")
        flash('Thanks for registering')
        return redirect(referer or url_for('home.show_places'))
    return render_template('signup.html', form=form, error=error)
Exemple #44
0
def signup():
    error = None
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Users(
            username=form.username.data,
            password=bcrypt.generate_password_hash(form.password.data)
            )
        try:
            db.session.add(user)
            db.session.commit()
            login_user(user)
            flash("You have just signup up congrats!", "success")
            return redirect(url_for("hello"))
        except:
            flash("That username already exists", "danger")
            return redirect(url_for("signup"))
    return render_template("signup.html", form=form, error=error)
Exemple #45
0
def register():
    """Displays registration form and handles user creation """
    form = RegistrationForm()
    if form.validate_on_submit():
        old_user = User.query.filter_by(username=form.username.data).first()
        if old_user is not None:
            flash('User {user} already exists'.format(user=form.username.data), 'error')
            return redirect((url_for('register')))
        old_user = User.query.filter_by(email=form.email.data).first()
        if old_user is not None:
            flash('{email} already used'.format(email=form.email.data), 'error')
            return redirect((url_for('register')))
        user = User(username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Please login to your new account'.format(user=form.username.data), 'info')
        return redirect((url_for('login')))
    return render_template('register.html',
                           title='Register',
                           form=form)
Exemple #46
0
def register():
    registration_form = RegistrationForm()
    if request.method == 'GET':
        return render_template('register.html', registration_form=registration_form)
    else:
        if registration_form.validate_on_submit():
            new_user = User(request.form['username'], request.form['email'], request.form['password'])
            new_email_verification = EmailVerification()
            new_email_verification.user_id = new_user.id
            new_user.emailverification = new_email_verification
            
            db.session.add(new_user)
            db.session.add(new_email_verification)
            db.session.commit()
            
            sendRegistrationEmail(new_user.email, new_user.username, new_email_verification.code)
            
            flash('Successfully registered. Check your email to confirm your account.', 'success')
            return redirect('/login')
        else:
            flash_errors(registration_form)
            return render_template('register.html', registration_form=registration_form)
Exemple #47
0
def sign_up():
    user_details = get_user_details()

    if is_user_registered(user_details[0]) and is_user_confirmed(user_details[0]):
        return redirect('/home')

    if is_user_registered(user_details[0]) and not is_user_confirmed(user_details[0]):
        return redirect(url_for('userManagement.unconfirmed'))

    r_form = RegistrationForm(request.form)
    if request.method == "GET":
        r_form.username.data = user_details[1]
        r_form.email.data = user_details[2]

    if r_form.validate_on_submit():
        user = User(username=r_form.username.data, email=r_form.email.data, eppn=user_details[0], role_id=2)
        db.session.add(user)
        db.session.commit()
        DirectoryAndFileWriter.create_user_directory(get_user_id(user_details[0]))
        send_email(current_app.config['ADMIN_MAIL_ADDRESS'], 'New user has registered', 'mail/new_user', user=user, comment=r_form.comment.data)
        return redirect(url_for('userManagement.unconfirmed'))

    return render_template('sign_up.html', r_form=r_form)