Ejemplo n.º 1
0
def signup():
    form = RegisterForm(request.form)
    if request.method == "POST":
        if form.validate():
            user = User(form.email.data, form.password.data)
            if user:
                user.name = form.name.data
                if user.second_name is not None:
                    user.second_name = form.second_name.data
                user.lastname = form.lastname.data
                if user.second_lastname is not None:
                    user.second_lastname = form.second_lastname.data 
                user.rfc = form.rfc.data
                # add company
                db.session.add(user)
                try:
                    db.session.commit()
                except IntegrityError:
                    db.session.rollback()
                    mess = "Either Email or the RFC exist in the database"
                    flash(mess)
                    return render_template("auth/signup.html", form=form, title="Sign Up")
                company = Company(form.company.data)
                company.user_id = user.id
                db.session.add(company)
                db.session.commit()
                flash("%s Signed Up successfuly with your Company %s" % (user.name, company.name))
                return redirect(url_for("auth.login"))
            flash("Something went wrong, please try again.", 'error-message')
        else:
            return jsonify(form.errors), 400
    return render_template("auth/signup.html", form=form, title="Sign Up")
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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,
            password=form.password.data,
        )
        db.session.add(user)
        db.session.commit()
        user = User.query.filter_by(username=form.username.data).first()
        email.send_register_confirmation(user)
        flash("Check your email to activate your account.")
        return redirect(url_for("auth.login"))
    return render_template("auth/form.html", title="Register", form=form)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def register():
    try:
        if current_user.is_authenticated:
            return redirect(url_for('main.homepage'))
        form = RegisterForm()
        if form.validate_on_submit():
            nUser = User.register(form)
            flash('Registrazione confermata per utente {}'.format(nUser.email))

            login_user(nUser)
            return redirect(url_for('main.homepage'))

        return redirect(url_for("auth.login"))
        #return render_template('auth/user/register.html', title="Register", form=form)
    except Exception as e:
        flash("Errore: " + str(e))
        return redirect(url_for("auth.login"))
Ejemplo n.º 7
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data.lower(),
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email,
                   'Account confirmation',
                   'auth/mail/confirm',
                   user=user,
                   token=token)
        flash('Account created,Login to continue')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Ejemplo n.º 8
0
def register():
    """Register new user."""
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = User.create(username=form.username.data,
                           email=form.email.data,
                           password=form.password.data,
                           active=False,
                           locale=g.locale)
        session['locale'] = user.locale
        flash(_('Thank you for registering. Please validate your email address before logging in.'),
              'success')
        send_confirm_email(user)
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('register.html', form=form)
Ejemplo n.º 9
0
def register():
    registerform = RegisterForm()
    if registerform.validate_on_submit():
        import pdb; pdb.set_trace();
        user_obj = User(name = registerform.name.data, 
            email = registerform.email.data, 
            username = registerform.username.data, 
            password = registerform.password.data,
            address = registerform.address.data
            )
        db.session.add(user_obj)
        db.session.commit()

        flash('You are now registered and can log in', 'success')

        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=registerform)
Ejemplo n.º 10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data)
        user.set_password(form.password.data)
        result = add_user_to_database(user, db.users)
        flash('You are now registered')
        send_email('Welcome!',
                   sender=current_app.config['ADMINS'][0],
                   recipients=[user.email],
                   text_body=render_template('email/welcome.txt', user=user),
                   html_body=render_template('email/welcome.html', user=user)
                   )
        current_app.logger.info(user.email + ' has registered')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
Ejemplo n.º 11
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("users.home"))

    form = RegisterForm()
    if form.validate_on_submit():
        user = {
            "name": form.name.data,
            "email": form.email.data,
            "password": form.password.data,
        }
        registered_user = User(**user)
        registered_user.save()
        send_welcome_email(user["name"], user["email"])

        flash("Registration successful, please login", category="success")
        return redirect(url_for("auth.login"))

    return render_template("auth/register.html", form=form)
Ejemplo n.º 12
0
def register():
    """[註冊頁面]
    """
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegisterForm()
    if form.validate_on_submit():
        # email為選填,區分2種情況處理
        if form.email.data:
            user = User(username=form.username.data, email=form.email.data)
            user.set_password(form.password.data)
        else:
            user = User(username=form.username.data)
            user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(u'註冊成功!請登入', 'success')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Ejemplo n.º 13
0
def register():
    form =RegisterForm()
    if form.validate_on_submit():
        user = User()
        user.nickname = form.nickname.data
        user.gen_password(form.password.data)
        user.email=form.email.data
        db.session.add(user)
        db.session.commit()

        token =user.gen_confirm_token()
        send_email(user.email, '博客账户确认',
                   'email_confirm', user=user, token=token)
        flash('已经发送确认邮件,请查收 --。- ~~.')
        #flash('成功注册')
        # login_user(user)
        return redirect(url_for('auth.login'))

    return render_template('auth/register.html', form=form)
Ejemplo n.º 14
0
def register():
    if current_user.is_authenticated:
        if current_user.admin:
            return redirect(url_for('main.users'))
        else:
            return redirect(url_for('main.homepage'))
    form = RegisterForm()
    if form.validate_on_submit():
        if User.query.filter_by(username=form.username.data).first():
            flash('Username already in use, please choose another')
            return redirect(url_for('auth.register'))
        if User.query.filter_by(email=form.email.data).first():
            flash('Email already in use')
            return redirect(url_for('auth.register'))
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        user.save_to_db()
        return redirect(url_for('auth.signin'))
    return render_template('auth/register.html', title='Register', form=form)
Ejemplo n.º 15
0
def register(token=None):
    """Login endpoint."""
    if token != "PASS360REG001":
        return redirect(url_for('index.index'))
    if current_user.is_authenticated:
        return redirect(current_user.get_landing_page())
    form = RegisterForm()
    return render_template('auth/register.html',
                           title='Register',
                           form=form,
                           token=token)
Ejemplo n.º 16
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)
        db.session.commit()

        # 发送邮件确认账户
        token = user.generate_confirmtion_token()
        send_mail(user.email,
                  "Confirm your Account!",
                  "auth/email/confirm",
                  user=user,
                  token=token)
        flash("我们已经给你发送了一封邮件!")
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form)
Ejemplo n.º 17
0
 def post(self):
     form = RegisterForm()
     if form.validate_on_submit():
         username = form.data['username']
         user = User.query.filter_by(user_name=func.binary(username)).first()
         if user:
             flash("账号已注册")
             return render_template("auth/login.html")
         registeruser = User(
             user_name=form.username.data,
             password=form.password.data,
             real_name=form.name.data,
             email=form.email.data,
             roles=[Role.query.filter_by(role_name='EMPLOYEE').first()])
         db.session.add(registeruser)
         db.session.commit()
         login_user(registeruser, False)
         return redirect(url_for("home.index"))
     else:
         flash(form.errors.popitem()[1][0])
         return render_template("auth/login.html")
Ejemplo n.º 18
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('user.dashboard'))
    form = RegisterForm()
    if request.method == 'POST':
        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('register.html', title='Register', form=form)
Ejemplo n.º 19
0
def register():
    form = RegisterForm()
    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_email(user.email,
                   'Confirm Your Account',
                   'auth/email/confirm',
                   user=user,
                   token=token)

        flash('Now you registered!')
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Ejemplo n.º 20
0
def reqister():
    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.password_again.data:
            return render_template('registr.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Пароли не совпадают")
        if db.session.query(User).filter(
                User.email == form.email.data).first():
            return render_template('registr.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Такой пользователь уже есть")
        if db.session.query(User).filter(
                User.username == form.username.data).first():
            return render_template('registr.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Такое имя уже занято")
        user = User(username=form.username.data,
                    email=form.email.data,
                    position=0)

        if request.files["file"]:
            file = request.files["file"]
            user.image = form.username.data + secure_filename(file.filename)
            f = open(
                current_app.config['UPLOAD_FOLDER'] + form.username.data +
                file.filename, 'wb')
            f.write(file.read())
            f.close()
        else:
            user.image = "no_user_foto.png"

        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect('/login')
    return render_template('auth/registr.html', title='Регистрация', form=form)
Ejemplo n.º 21
0
def register():
    #  if user is logged in, redirect
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    regForm = RegisterForm()
    if regForm.validate_on_submit():
        #  create object user from app.models with the following attributes
        user = User(
            username=regForm.username.data,
            email=regForm.email.data,
        )

        user.set_password(regForm.password.data)
        user.set_default_avatar_hash()
        #  add user and commit into the database
        db.session.add(user)
        db.session.commit()
        send_confirmation_email(user)  # send activation link to user's email
        flash('A confirmation email has been sent.', 'success')
        return redirect(url_for('main.index'))
    return render_template('auth/register2.html', regForm=regForm)
Ejemplo n.º 22
0
def signup():
    name_button = 'Sign Up'
    html_file = get_html_file(request.referrer)

    # Form used to register user.
    form = RegisterForm()

    # When form is submitted with all fields correctly filled
    # NOTE: username verification uses a method inside the class RegisterForm in forms.py
    if form.validate_on_submit():
        # Create new user entry
        user = User(username=form.username.data, fname=form.fname.data, lname=form.lname.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        # Does not automatically login user
        # User is redirected to login page to officially login
        return redirect(url_for('auth.login'))

    # Display signup page
    return render_template("auth/Stargazer_signup.html", title='Create Account', form=form, prev_temp=html_file, name_button=name_button)
Ejemplo n.º 23
0
def register_user():
    if request.method == "GET":
        return render_template("auth/registerform.html", form=RegisterForm())

    form = RegisterForm(request.form)

    # Existing user check & form validation
    user = User.query.filter_by(username=form.username.data).first()
    if (user):
        return render_template("auth/registerform.html",
                               form=form,
                               error="Username " + form.username.data +
                               " is in use!")
    if not form.validate():
        return render_template("auth/registerform.html", form=form)

    pw_hash = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
    new_user = User(form.username.data, pw_hash)

    db.session().add(new_user)
    db.session().commit()

    return redirect(url_for("auth_login", regSuccess="1"))
Ejemplo n.º 24
0
def register(user_repository: UserRepository):
    form = RegisterForm(request.form)

    if request.method == 'POST' and form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    phone_number=form.telephone.data)
        try:
            user_repository.add(user)
        except UserAlreadyRegisteredException:
            flash(
                'Username or email already exists. Please login or try something else',
                'error')
            return redirect(url_for('auth.register'), 303)

        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('auth.login'), 302)

    return render_template('register.html', form=form)
Ejemplo n.º 25
0
def register():
    from app.auth.forms import RegisterForm
    form = RegisterForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None:
            flash(u'该账号已经注册过了')
            return render_template('register.html', form=form)
        user = User(username=form.username.data,
                    password=form.password.data,
                    email=form.email.data)  # 新添加一个用户到数据库中
        db.session.add(user)
        db.session.commit()
        User.add_self_follows()  # 把自己添加成自己的关注
        token = user.generate_confirm_token()  # 产生一个令牌
        send_mail(user.email, u'请确认您的帐号', 'confirm', user=user,
                  token=token)  # 发送邮件
        flash(u'有一份邮件已经发往您的邮箱')
        # return redirect(url_for('auth.login'))    # 这一步一直有问题,无法重定向,直接跳到下面去了
        login_user(user)
        return redirect(url_for('auth.unconfirmed'))
    else:
        return render_template('register.html', form=form)
Ejemplo n.º 26
0
 def create_user(self, num=50):
     for i in range(1, num + 1):
         file_name = f'media\\avatar\\{random.randint(1, 43)}.jpg'
         with open(file_name, 'rb') as f:
             user = User()
             form = RegisterForm()
             form.name.data = f'test{i}'
             form.email.data = f'test{i}@test.com'
             form.phone.data = '131' + ''.join(
                 str(random.randint(0, 9)) for _ in range(8))
             form.avatar.data = FileStorage(f)
             form.password.data = '123asd'
             form.repassword.data = '123asd'
             user.confirm = 1
             user.intro = 'normal user'
             user.auth = AuthEnum.User
             user.role = RoleEnum.User
             user.add(form, record_log=False)
Ejemplo n.º 27
0
 def create_super_admin(self):
     if User.query.filter_by(email='*****@*****.**').first():
         return
     file_name = f'media\\avatar\\{random.randint(1, 43)}.jpg'
     with open(file_name, 'rb') as f:
         user = User()
         form = RegisterForm()
         form.name.data = 'super_admin'
         form.email.data = '*****@*****.**'
         form.phone.data = '98765432121'
         form.avatar.data = FileStorage(f)
         form.password.data = '123asd'
         form.repassword.data = '123asd'
         user.confirm = 1
         user.intro = 'super admin'
         user.auth = AuthEnum.SuperAdmin
         user.role = RoleEnum.SuperAdmin
         user.add(form, record_log=False)
Ejemplo n.º 28
0
 def test_post(client, mocker):
     mocker.patch("app.auth.email.send_register_confirmation")
     form = RegisterForm(
         username="******",
         email="*****@*****.**",
         password="******",
         password2="password",
     )
     response = client.post(
         url_for("auth.register"),
         data=form.data,
         follow_redirects=True,
     )
     assert response.status_code == 200
     user = User.query.filter_by(username=form.username.data).first()
     assert user.username == "new_test_user"
     email.send_register_confirmation.assert_called_once_with(user)
     assert b"Check your email to activate your account." in response.data
Ejemplo n.º 29
0
def register_view():
    # check whether user has already login
    if current_user.is_authenticated:
        return redirect(url_for('auth.home_view', account_id=current_user.account_id))

    # main function process below
    form = RegisterForm()
    captcha = dict()
    captcha_url = 'http://' + Config.CAPTCHA_SERVICE_URL + '/api/hash-match/captcha'
    result = requests.get(captcha_url)
    if result.status_code == 200:
        captcha['captcha_code'] = get_api_info(result)[0]['CAPTCHA']
        captcha['hash_code'] = get_api_info(result)[0]['Hash-Code']
        # store the captcha code into session
        session['captcha_code'] = captcha['captcha_code']
        captcha['captcha_url'] = 'http://' + Config.CAPTCHA_SERVICE_URL +\
                                 '/api/hash-match/captcha/' + captcha['hash_code']
    else:
        captcha['captcha_code'] = '0000'
        captcha['captcha_url'] = 'error'
    return render_template('auth/register/register.html', form=form, captcha=captcha)
Ejemplo n.º 30
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.homepage'))

    form = LoginForm()
    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        try:
            user = User.login(email, password)
        except:
            flash('Invalid Username or Password')
            return redirect(url_for('auth.login'))

        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('main.homepage'))

    register_form = RegisterForm()
    reset_form = RequestPasswordForm()
    return render_template('auth/user/login.html',
                           title="Login",
                           login_form=form,
                           register_form=register_form,
                           reset_form=reset_form)
Ejemplo n.º 31
0
def register_view():
    form = RegisterForm()
    return render_template('auth/register/register.html', form=form)
Ejemplo n.º 32
0
def inject_user_forms():
    g.login_form = LoginForm()
    g.register_form = RegisterForm()
    g.reset_form = RequestPasswordForm()
Ejemplo n.º 33
0
 def test_register(self):
     form = RegisterForm(username='******',
                         email='*****@*****.**',
                         password='******',
                         confirm='123')
     self.assertTrue(form.validate() is True)