Exemple #1
0
def register():
    # """Register user"""
    # https://flask.palletsprojects.com/en/1.1.x/patterns/wtforms/

    # Both of these lines work - I am using the fist form
    form = RegisterForm()
    #form = RegisterForm(request.form)

    # Either if request.method == "POST" OR form.validate_on_submit(): works
    # The form.validate_on_submit() method does all the form processing work.
    # https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms

    # if request.method == "POST":

    if form.validate_on_submit():
        user = People(username=form.username.data,
                      email=form.email.data,
                      first_name=form.first_name.data,
                      last_name=form.last_name.data,
                      comments=form.password.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        #flash('Register requested for user {}, firstName={}, lastName={}'.format(
        #    form.username.data, form.firstName.data, form.lastName.data))
        flash(
            'Congratulations, you are now a registered user!<br>Please Log In.',
            "success")
        return redirect(url_for('auth.login'))

    form.submit.label.text = 'Register'
    return render_template('auth/register.html', title='Register', form=form)
Exemple #2
0
def register_submit(token=None):
    """Login endpoint."""
    if token != "PASS360REG001":
        return redirect(url_for('index.index'))

    form = RegisterForm()
    if form.validate_on_submit():
        email = form.email.data
        user = User.get(email=form.email.data)
        if user:
            flash('That email is already taken')
        else:
            user = User(email=email)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()

            send_confirm_email(user)
            login_user(user)
            flash("Your account has been successfully created.")
            return redirect(user.get_landing_page())
    return render_template('auth/register.html',
                           title='Register',
                           form=form,
                           token=token)
Exemple #3
0
def register_account():
    # check whether user has already login
    if current_user.is_authenticated:
        return redirect(url_for('auth.home_view', account_id=current_user.account_id,
                                _external=True, _scheme='https'))

    # main function process below
    form = RegisterForm()
    # POST method
    if form.validate_on_submit():
        # captcha validate ( get from session )
        if str(form.captcha.data).upper() != session.get('captcha_code'):
            flash('CAPTCHA is not Correct!', 'warning')
            return redirect(url_for('auth.register_view', _external=True, _scheme='https'))
        if form.password.data != form.re_password.data:
            flash('Passwords should be the same.', 'warning')
            return redirect(url_for('auth.register_view', _external=True, _scheme='https'))
        # account info
        account_info = dict()
        account_info['account_email'] = form.email.data
        account_info['account_nickname'] = form.nickname.data
        account_info['password'] = form.re_password.data
        register_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/account-creating'
        result = requests.post(register_url, data=account_info)
        if result.status_code == 200:
            account = get_api_info(result)[0]
            return redirect(url_for('auth.login_view', account_id=account['account_id'],
                                    _external=True, _scheme='https'))
        else:
            flash('Please use an different email address.', 'danger')
            return redirect(url_for('auth.register_view', _external=True, _scheme='https'))
Exemple #4
0
def signup():
    """
    Handle requests to the /signup route
    Add an user to the database through the registration form
    """
    form = RegisterForm()
    if form.validate_on_submit():
        email = form.email.data
        # Add a check for specific email domain
        # dumb trick
        if email.endswith('@example.com'):
            user = User(email=form.email.data,
                        name=form.name.data,
                        password=form.password.data)
            user.is_admin = False

            # add user to the database
            db.session.add(user)
            db.session.commit()
            flash('You have successfully registered! You may now login.')

            # redirect to the login page
            return redirect(url_for('auth.signin'))
        else:
            # redirect to the login page as the email domain does not match
            flash("Sorry, We are not accepting users at this time.")
            return redirect(url_for('home.index'))

    # load registration template
    return render_template('auth/signup.html', form=form)
Exemple #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        if user.email == current_app.config['FLASK_ADMIN']:
            user.confirmed = True
        db.session.add(user)
        db.session.commit()

        if user.email != current_app.config['FLASK_ADMIN']:
            token = user.generate_confirmation_token()
            print('TOKEN: ' + token)
            send_email(user.email,
                       'Confirm your account',
                       'auth/mail/confirm',
                       user=user,
                       token=token)
            flash(
                'A confirmation mail has been sent to you by email, check your spam folder!'
            )
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
Exemple #6
0
def render_register():
    if current_user.is_authenticated:
        return redirect(url_for('main.render_index'))
    form = RegisterForm()
    if form.validate_on_submit():
        check_user_username = db.session.query(User).filter(
            User.username == form.username.data).first()
        check_user_email = db.session.query(User).filter(
            User.email == form.email.data).first()
        if not check_user_email and not check_user_username:
            user = User(username=form.username.data, email=form.email.data)
            user.set_password(form.password.data)
            if form.is_admin.data == current_app.config['KEY_WORD_FOR_BOSS']:
                user.is_boss = True
            db.session.add(user)
            db.session.commit()
            flash(
                'Поздравляю, Ты зарегистрировался в сервисе! Не забудь проверить электронную почту!'
            )
            send_email('Регистрация',
                       recipients=[user.email],
                       html_body=render_template('email/email_register.html',
                                                 user=user))
            return redirect(url_for('auth.render_login'))
        else:
            flash('Пользователь с таким логином или почтой уже существует!')
            return redirect(url_for('auth.render_register'))
    return render_template('auth/register.html',
                           form=form,
                           title='Регистрация')
Exemple #7
0
def sign_up():
    if current_user.is_authenticated:
        flash('Log out to create new account', 'warning')
        return redirect(url_for('main.index'))

    form = RegisterForm()

    if form.validate_on_submit():
        # Lookup for an existing user
        user_exist = User.query.filter_by(phone=form.phone.data).first()
        if user_exist:
            flash('This phone number is already registered', 'warning')
        else:
            user = User()
            user.phone = form.phone.data
            user.set_password(form.password.data)
            try:
                db.session.add(user)
                db.session.commit()
                flash('Registered successfully', 'success')
                return redirect(url_for('auth.sign_in'))
            except IntegrityError as e:
                flash('Some errors occured, try later', 'warning')
                db.session.rollback()
    return render_template('auth/signup.html', form=form)
Exemple #8
0
def register():
    ''' check if user is logged in '''
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    form = RegisterForm()
    if form.validate_on_submit():
        unique_id = uuid.uuid4().int & (1 << 29) - 1
        user = User(username=form.username.data,
                    uuid=unique_id,
                    email=form.email.data,
                    timezoneoffset=form.timezone.data)
        user.set_password(form.password.data)

        db.session.add(user)
        db.session.commit()

        newuser = User.query.filter_by(uuid=unique_id).first()
        login_user(newuser, remember=True)

        token = newuser.generate_confirmation_token()
        send_email(user=newuser, token=token)

        next = url_for('auth.confirm_account')

        return redirect(next)

    return render_template('register.html', form=form)
Exemple #9
0
def register():
    form = RegisterForm(request.form)

    if form.validate_on_submit():
        # create a user instance not yet stored in the database
        user = User(name=form.name.data,
                    email=form.email.data,
                    password=generate_password_hash(form.password.data))

        try:
            db.session.add(user)
            db.session.commit()
        except IntegrityError:
            flash(
                'Check if your input is correct, else the username or email might already be in use.'
            )
            return redirect(url_for('auth.register'))

        # Log the user in
        login_user(user)

        # flash will display a message to the user
        flash('Thanks for registering')
        # redirect user to the 'home' method of the user module
        return redirect(url_for('todo.index'))
    return render_template('auth/register.html', form=form)
Exemple #10
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).count()
        if not user:
            user_add = User(name=form.name.data,
                            email=form.email.data,
                            password=form.password.data)
            db.session.add(user_add)
            db.session.commit()
            send_mail("用户注册提示",
                      current_app.config["GRADUATION_MAIL_SENDER"],
                      [current_app.config["GRADUATION_MAIL_ADMIN"]],
                      "auth/remind_admin/remind_admin",
                      user=user_add)
            token = user_add.generate_confirmed_token()
            send_mail("账户确认",
                      current_app.config["GRADUATION_MAIL_SENDER"],
                      [user_add.email],
                      "auth/confirm_auth/confirm",
                      token=token,
                      user=user_add)
            flash("注册成功!有一封邮件已发送至您的邮箱请前往确认!")
            return redirect(url_for("auth.login"))
        else:
            flash("邮箱已被注册!")
            return redirect(url_for("auth.register"))
    return render_template("auth/register.html", form=form)
Exemple #11
0
def register():
    form = RegisterForm()
    if request.method == "POST" and form.validate_on_submit():
        #Verificando que el usuario aun no se haya registrado
        user = User.query.filter_by(email=form.email.data).first()
        if (user):
            flash(_("The email %(email)s is already in use"),
                  email=form.email.data)
            return redirect(url_for('auth.register'))

        address = Address(city=form.city.data,
                          state=form.state.data,
                          municipality=form.municipality.data,
                          street=form.street.data,
                          postal_code=form.postal_code.data,
                          interior_number=form.interior_number.data,
                          exterior_number=form.exterior_number.data)
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    addresses=[address])
        user.set_password(form.password.data)
        user.set_user_secret(form.email.data)
        db.session.add(user)
        db.session.commit()
        send_registration_email(user)
        flash(
            _("Congratulations you are a registered user, please confirm your email %(email)s!",
              email=form.email.data))

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

    return render_template('auth/register.html', form=form)
def register_account():
    # auth process
    if current_user.is_authenticated is True:
        account = get_account_info_by_account_id(current_user.account_id)
    else:
        return redirect(url_for('auth.login_view'))
    if account['account_status'] != 'admin':
        return redirect(url_for('auth.home_view'))
    # process end

    # main function process below
    form = RegisterForm()
    # POST method
    if form.validate_on_submit():
        # captcha validate ( get from session )
        if str(form.captcha.data).upper() != session.get('captcha_code'):
            flash('CAPTCHA is not Correct!', 'warning')
            return redirect(url_for('auth.register_view'))
        if form.password.data != form.re_password.data:
            flash('Passwords should be the same.', 'warning')
            return redirect(url_for('auth.register_view'))
        # account info
        account_info = dict()
        account_info['account_email'] = form.email.data
        account_info['account_nickname'] = form.nickname.data
        account_info['password'] = form.re_password.data
        account_info['account_status'] = form.account_status.data
        register_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/account-creating'
        result = requests.post(register_url, data=account_info)
        if result.status_code == 200:
            flash('新用户创建成功!', 'success')
            return redirect(url_for('auth.register_view'))
        else:
            flash('该邮箱已被注册。', 'danger')
            return redirect(url_for('auth.register_view'))
Exemple #13
0
def register():
    
    form = RegisterForm()
    if form.validate_on_submit():
        unique_id = uuid.uuid4().int & (1<<29)-1
        user = User(username=form.username.data, 
            uuid = unique_id,
            email=form.email.data)
        details = UserDetail(user_uuid=unique_id,
            login_type=1) 
        user.set_password(form.password.data)

        db.session.add(user)
        db.session.add(details)
        db.session.commit()

        newuser = User.query.filter_by(uuid = unique_id).first()
        login_user(newuser, remember=True)

        token = newuser.generate_confirmation_token()
        confirm_email(user=newuser, token=token)
    
        next = url_for('main.home')
            
        return redirect(next)
        
    return render_template('register.html', form=form)
Exemple #14
0
def register():
    from app.auth.forms import RegisterForm
    form = RegisterForm()
    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()
        # 生成用户头像文件夹
        UPLOAD_FOLDER = current_app.config['UPLOAD_FOLDER']
        avatar_path = '{}/{}'.format(UPLOAD_FOLDER, user.username)
        isExists = os.path.exists(avatar_path)
        if not isExists:
            os.makedirs(avatar_path)
            # print('创建成功')

        User.add_self_follows()  # 把自己添加成自己的关注
        token = user.generate_confirm_token()  # 产生一个令牌
        send_mail(user.email, u'请确认您的帐号', 'confirm', user=user,
                  token=token)  # 发送邮件
        flash(u'有一份邮件已经发往您的邮箱')
        login_user(user)
        return redirect(url_for('auth.login'))  # 这一步一直有问题,无法重定向,直接跳到下面去了
    else:
        return render_template('register.html', title=u'注册', form=form)
Exemple #15
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        new_user = userService.add(form.username.data, form.email.data, form.password.data)
        login_user(new_user)
        flash('You are now registered', 'success')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form)
Exemple #16
0
def register():
    form = RegisterForm()
    print(form.validate_on_submit())
    flash(form.errors)
    # if request.method == 'POST' and form.validate():
    if form.validate_on_submit():
        new_user = User(name=form.name.data, username=form.username.data,
                        email=form.email.data, password=form.password.data)
        db.session.add(new_user)
        db.session.commit()
        send_email(form.email.data, 'Account Confirmation Email',
                   'auth/email/confirm', token=new_user.generate_confirmation_token(), user=new_user)
        # print(form.name.data)
        flash('You have registered your account successfully.' + \
              ' An account confirmation email has been sent to your email. Please login and confirm your account.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Exemple #17
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        flash('You can now login.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Exemple #18
0
def register():
    """User registration view controller"""
    title = 'User registration'
    form = RegisterForm()
    if form.validate_on_submit():
        User.save_user(username=form.username.data, email=form.email.data, password=form.password.data)
        flash('Congratulations you are now a registered user!')
        return redirect(url_for('auth.login'))

    return render_template('auth/register.html', title=title, form=form)
Exemple #19
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        #ajeitar isso aqui quando estiver codificando as rotas
        avatar = "vsvskvjsdvsv"
        user = User(form.username.data, form.email.data, form.password.data, avatar)
        user.save()
        #consertar isso aqui.
        return render_template("auth/teste.html", msg="Seu cadastro foi realizado com sucesso, Larry.")
    return render_template("auth/login.html", form=form)
Exemple #20
0
def register():
    form = RegisterForm()
    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(_('注册成功!'), 'success')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Exemple #21
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegisterForm()
    if form.validate_on_submit():
        u = User(username=form.username.data)
        u.set_password(form.password.data)
        u.save()
        flash('You are now registered')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Exemple #22
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        new_user = User(username=form.username.data)
        new_user.set_password(form.password.data)
        new_user.save()
        flash('注册成功')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form, title='注册')
Exemple #23
0
def signup():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('注册成功!', 'info')
        return redirect(url_for('auth.signin'))

    return render_template('/auth/signup.html', form=form)
Exemple #24
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('core.index'))
    form = RegisterForm()
    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 been registered.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Sign Up', form=form)
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegisterForm()
    if form.validate_on_submit():
        u = User(email=form.email.data)
        u.set_password(form.password.data)
        db.session.add(u)
        db.session.commit()
        login_user(user)
        return redirect(url_for('main.index'))
    return render_template('auth/register.html')
Exemple #26
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegisterForm()
    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('auth.login'))
    return render_template('auth/register.html', title=_('Register'), form=form)
Exemple #27
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegisterForm()
    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 registered! Login to continue.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
Exemple #28
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        if User.query.filter_by(name=form.username.data).first():
            flash(f'[{form.username.data}] is already exist.',
                  category='danger')
            return redirect(url_for('auth.register'))
        else:
            User.create(form.username.data, form.password.data)
            flash('Registration completed')
            return redirect(url_for('auth.register'))
    return render_template('auth/register.html', title='Register', form=form)
Exemple #29
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("main.feed"))
    form = RegisterForm()
    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("auth.login"))
    return render_template("auth/register.html", title="Register", form=form)
Exemple #30
0
def signup():
    form = RegisterForm()
    if form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        password = form.password.data
        user = User(username=username, email=email)
        user.set_password(password)
        user.save()
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('auth.login'))
    return render_template('auth/signup.html', title='Sign Up', form=form, current_user=current_user)
Exemple #31
0
def register():
    if g.auth is not None and g.auth.is_authenticated():
        return redirect(url_for('index'))

    form = RegisterForm()

    if form.validate_on_submit():

        if form.password.data != form.password_confirm.data:
            flash('Your passwords were not the same.')
            return redirect(url_for('register'))


        user = None
        auth = None
        user = UserBasic.query.filter_by(email = form.email.data).first()

        if user and user.role == USER.MAILLIST:
            user.nickname = form.email.data.split('@')[0]
            user.maillist=True
            
            auth = UserAuth()
            auth.hpass  = bcrypt.generate_password_hash(form.password.data)
            auth.role   = USER.USER
            auth.status = USER.NEW

            db.session.commit()
            return redirect(url_for('index'))
        else:
            flash('That email address is already in use.')
            return redirect(url_for('register'))

        user = UserBasic(email=form.email.data,
                    nickname = form.email.data.split('@')[0],
                    maillist=True)
        
        auth = UserAuth()
        auth.hpass  = bcrypt.generate_password_hash(form.password.data)
        auth.role   = USER.USER
        auth.status = USER.NEW

        db.session.add(user)
        db.session.add(auth)
        db.session.commit()

        if auth:
            flash('Registration successful.')
            return redirect(url_for('index'))

        else:
            flash('Failed to register user...')
    return render_template('auth/register.html', form=form)
Exemple #32
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('feed.feed'))
    form = RegisterForm()
    if form.validate_on_submit():

        ip_client = request.remote_addr
        genre = "Masculino"
        date = "1999-11-28"
        user = Users(username=form.username.data, email=form.email.data,
                     password_hash=form.password.data, first_name=form.first_name.data, genre=genre, date_birth=date, device_ip_register=ip_client)
        controller = UsersController()
        controller.save_new_user(user)
        send_confirm_email(user)
        return render_template("auth/confirm_email_msg.html", user=user)
    return render_template("auth/register.html", form=form)