Exemplo n.º 1
0
def registration():
    if request.method == 'GET':
        return render_template('auth/registration.html', title='Registration',
                               form=RegistrationForm())

    form = RegistrationForm()
    username = form.username.data
    full_name = form.full_name.data
    email = form.email.data
    password = form.password.data

    if form.validate_on_submit():
        try:
            mongo.db.users.insert({'_id': username,
                                   'full_name': full_name,
                                   'email': email,
                                   'password': User.generate_hash(password),
                                   'registered_in': datetime.datetime.utcnow()
                                   })

            flash('Successfully created an account!', category='success')
            send_email(email, full_name, username, password)
            return redirect(url_for("auth.login"))
        except DuplicateKeyError:
            flash('Username already exist', category='error')
    return render_template('auth/registration.html', form=form)
Exemplo n.º 2
0
def register():
    form = RegistrationForm()
    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)
Exemplo n.º 3
0
def register():
    form = RegistrationForm()
    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_confirm_token()
        send_email(user.email, "Confirm Your Account", "auth/email/confirm", user=user, token=token)
        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)
Exemplo n.º 4
0
def register():
    from app.auth.forms import RegistrationForm
    form=RegistrationForm()
    if form.validate_on_submit():
        user=User(email=form.email.data,
                  name=form.username.data,
                  password=form.password.data
                  )
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('auth.login'))
    return render_template('register.html',title=u'注册',form=form)
Exemplo n.º 5
0
def register():
    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_email(user.email, 'Confirm your Account.', 'auth/email/confirm', user=user, token=token)

        flash('A confirmation email have been sent to you by email.')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form)
Exemplo n.º 6
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)
        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)
Exemplo n.º 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)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email, 'Xác nhận tài khoản của bạn',
                   'auth/email/confirm', user=user, token=token)
        flash(_('Một thư xác nhận đã được gửi tới địa chỉ email đăng ký'))
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Exemplo n.º 8
0
def register():
    form = RegistrationForm(request.form)

    if request.method == "POST":
        if form.validate_on_submit():
            print(form.data)
            user = User(email=form.data['email'], username=form.data['username'], password=form.data['password'],
                        is_admin=False)
            db.session.add(user)
            db.session.commit()
            login_user(user, True)
            flash("Registered successfully")
            return redirect(url_for("questions.index"))
    return render_template("register.html", form=form)
Exemplo n.º 9
0
def admin_register():
    """
    内部工作人员注册
    :return:
    """
    form = RegistrationForm()
    if form.validate_on_submit():
        user = AdminUser(email=form.email.data,
                         user_name=form.username.data,
                         password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email, current_app.config['FLASK_MAIL_SENDER'],
                   'Admin', gettext('Confirm Your Account'), 'auth/confirm',
                   user=user, token=token, host=request.url_root, name=user.user_name)
        flash(gettext('A confirmation email has been sent to you be email.'))
        return redirect(url_for('auth.admin_login'))
    return render_template('auth/register.html', form=form)
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        password = form.password.data
        location = form.location.data
        description = form.description.data
        role = form.role.data

        user = User(username, email, password, location, description, role)
        db.session.add(user)
        db.session.commit()
        flash("You are registered", "success")
        login_user(user)
        user.create_activation_token()
        db.session.commit()
        # Send activation email
        return redirect(url_for("main.home"))

    return render_template("register.html", form=form)
Exemplo n.º 11
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        numUtenti=User.query.count()
        if numUtenti < 1:
            user = User(username=form.username.data, email=form.email.data, cellular=form.cellular.data, is_admin=True, is_active=True)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
        else: 
            user = User(username=form.username.data, email=form.email.data, cellular=form.cellular.data, is_admin=False, is_active=False)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            admin = User.query.filter_by(is_admin=True).first()
            admin.add_notification('registration_request', admin.new_requests())
            db.session.commit()
        flash('Congratulazioni, ora sei un utente registrato!')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Registrazione', form=form)
Exemplo n.º 12
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)
        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'))
    typeName = None
    if auth.current_login_type == LoginType.REGISTE_MANAGE:
        typeName = 'Registe Manage'
    if auth.current_login_type == LoginType.WEB_APP_MANAGE:
        typeName = 'Web App Manage'
    if auth.current_login_type == LoginType.TENANT_SERVICE:
        typeName = 'Tenant Service'
    return render_template('auth/register.html',
                           title=_('Register'),
                           form=form,
                           typeName=typeName)
Exemplo n.º 13
0
def register():
    """ Handle requests to the /register route. Add a user to the database
    through the registration form. """
    form = RegistrationForm()
    if form.validate_on_submit():
        # First user added will be granted admin privileges
        is_admin = (db.session.query(User).count() == 0)

        user = User(email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    password=form.password.data,
                    is_admin=is_admin)

        current_app.logger.info('Registering new user {}'.format(user))

        # Add user to the database
        try:
            db.session.add(user)
            db.session.commit()
        except Exception as e:
            current_app.logger.exception(e)
            raise exc.UserCreateError()

        # Update current_user by logging user in
        login_user(user)

        # Notify user
        send_new_user_email(current_user.to_dict())
        flash('You have successfully registered, and now you are logged in!')

        # Redirect user to home page
        return redirect(url_for('home.main'))

    # Load registration template
    return render_template('form.html',
                           form=form,
                           title='Register',
                           description='To login, please register an account!')
Exemplo n.º 14
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()

    if form.validate_on_submit():
        check_user = User.query.filter_by(email=form.email.data).first()
        if not check_user:
            user = User(email=form.email.data,
                        first_name=form.first_name.data,
                        last_name=form.last_name.data,
                        messenger_type=form.messenger_type.data,
                        messenger=form.messenger.data)

            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Registration completed successfully')
            return redirect(url_for('auth.login'))
        else:
            flash('Sorry, email already exist.')
    return render_template('auth/register.html', form=form)
Exemplo n.º 15
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    session['mssg'] = ""
    if form.validate_on_submit():
        if str(form.key.data) == "admin":
            user = User(username=form.username.data)
            user.set_password(form.password.data)
            role = Role.query.filter_by(name="ADMIN").first()
            user.roles.append(role)
            db.session.add(user)
            db.session.commit()
            session[
                'mssg'] = "Thanks for Signing Up . Please login to use Hafta"
            return redirect(url_for('auth.login'))
        else:
            session['mssg'] = "Invalid Key"
    return render_template('auth/register.html',
                           title='Register',
                           form=form,
                           mssg=session['mssg'])
Exemplo n.º 16
0
def register():
   # if current_user.is_authenticated:
   #     return redirect(url_for('home.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(UserName=form.username.data)
        new_salt = set_user_salt()
        hashed_password = hash_password(new_salt, form.password.data)
        new_user = create_user(
            role=form.role.data, 
            username=form.username.data, 
            firstname=form.firstname.data,
            lastname=form.lastname.data,
            passwordhash=hashed_password,
            passwordsalt=new_salt)
        if new_user == 'OK':
            flash('Registrace proběhla úspěšně.')
            #return redirect(url_for('auth.login'))
        else:
            flash('Bohužel, registrace byla neúspěšná.')

    return render_template('auth/register.html', title='Register', form=form)
Exemplo n.º 17
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("main.show_user", username=current_user.username))

    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(
            username=form.username.data,
            email=form.email.data.lower(),
            player_level=form.player_level.data,
            player_team=form.player_team.data,
            email_registered=False,
        )
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        send_confirm_email(user)
        flash("A confirmation link has been sent via email.", "success")
        return redirect(url_for("auth.login"))

    return render_template("auth/register.html", title="Register", form=form)
Exemplo n.º 18
0
def index():
    """Register a new user and send them a confirmation email."""

    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    login_form = LoginForm()
    registration_form = RegistrationForm()

    if registration_form.register.data and registration_form.validate_on_submit(
    ):
        user = User(first_name=registration_form.first_name.data,
                    last_name=registration_form.last_name.data,
                    email=registration_form.email.data,
                    password=registration_form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('auth.confirm', token=token, _external=True)
        return redirect(url_for('auth.login'))

    if login_form.login.data:
        if login_form.validate_on_submit():
            user = User.query.filter_by(email=login_form.email.data).first()
            if user is None or not user.check_password(
                    login_form.password.data):
                flash('Invalid email or password.', 'danger')
                return redirect(url_for('auth.login'))
            login_user(user, remember=login_form.remember_me.data)
            next_page = request.args.get('next')
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('main.home')
            return redirect(next_page)
        flash('Invalid email or password.', 'danger')
        return redirect(url_for('auth.login'))

    return render_template('auth/index.html',
                           login_form=login_form,
                           registration_form=registration_form)
Exemplo n.º 19
0
def register():

    if current_app.config['OPEN_REGISTRATION'] is False:
        if not current_user.is_authenticated:
            flash(
                _('Registration is not open, contact admin to get an account'))
            return redirect(url_for('main.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()

        Audit().auditlog_new_post('user',
                                  original_data=user.to_dict(),
                                  record_name=user.username)
        flash(_('Congratulations, you are now a registered user!'))
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html',
                           title=_('Register'),
                           form=form)
Exemplo n.º 20
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,
                    confirmed=False)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('auth.confirm_email',
                              token=token,
                              _external=True)
        html = render_template('auth/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(subject, user.email, html)
        login_user(user)
        #flash('A confirmation email has been sent.')
        #return redirect(url_for('main.user', username=user.username))
        return redirect(url_for('auth.unconfirmed'))
    return render_template('auth/register.html', form=form)
Exemplo n.º 21
0
def register():  # регистрация
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()  # инициализация форм указанных в forms.py
    cursor = conn.cursor()
    if form.validate_on_submit():
        fio = form.familiya.data + ' ' + form.imya.data + ' ' + form.otchestvo.data
        cursor.execute(
            'insert into Uzer (fio,phone,gender,dyennarodjenya,login,password,avatar) values(%s,%s,%s,%s,%s,%s,%s)',
            [
                fio, form.phone.data, form.gender.data, form.dr.data,
                form.login.data,
                generate_password_hash(form.password.data),
                'https://sun9-31.userapi.com/c622218/v622218469/3809c/DVjj0zqmizo.jpg'
            ])
        conn.commit()  # добавление данных введенных при регистрации в БД
        flash(_('Учетная запись для %(fio)s создана успешно!', fio=fio))
        flash(_('Login: %(login)s', login=form.login.data))
        flash(_('Password: %(passw)s', passw=form.password.data))
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html',
                           title=_('Register'),
                           form=form)
Exemplo n.º 22
0
def admin_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,
                    secure_token=token_urlsafe())
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        role = Role(user_id=user.id, secure_token=token_urlsafe(16))
        role.set_admin()

        db.session.add(role)
        db.session.commit()

        flash('Congratulations, you are now a registered Admin!')
        return redirect(url_for('auth.admin_login'))
    return render_template('auth/admin/register.html',
                           title=_('Admin - Register'),
                           form=form)
Exemplo n.º 23
0
def register():
    if current_user.is_authenticated:
        flash('You are already logged in.')
        return redirect(url_for('main.index'))

    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(email=form.email.data)
        user.hash_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        token = gen_token(user.email)
        send_email(to=user.email, subject='Confirm Your Account',
               template='auth/confirm/confirm', user=user, token=token)

        login_user(user)

        flash('A confirmation email has been sent.', 'success')
        return redirect(url_for('main.index'))

    return render_template('auth/register.html', title="Register", form=form)
Exemplo n.º 24
0
def register():
    error = ' '
    form = RegistrationForm()
    if current_user.is_authenticated:
        return redirect(url_for('home.homepage'))
    try:
        if form.validate_on_submit():
            user = User(firstname=form.firstname.data,
                        lastname=form.lastname.data,
                        email=form.email.data,
                        phonenumber=form.phonenumber.data)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            gc.collect()
            flash("Congratulations, Registration was successful", 'success')
            return redirect(url_for('auth.login'))
        return render_template('register.html',
                               form=form,
                               error=error,
                               title='Register')
    except Exception as e:
        return render_template('register.html', form=form, title="Register")
Exemplo n.º 25
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)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(_('Félicitations, tu fais maintenant partie de notre grande famille !'))
#        try :
#            conn = mysql.connector.connect(host="130.79.207.104",user="******",password="******",database="pia")
#            cursor = conn.cursor()
#            cursor.execute("SELECT id from user;")
#            result = cursor.fetchall()
#            args=result[-1]
#            cursor.callproc('sp_InsertIntoAll',args)
#            cursor.close()
#            conn.commit()
#        except mysql.connector.Error as error:
#            print("Failed to execute stored procedure: {}".format(error))
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title=_('Inscription'),form=form)
Exemplo n.º 26
0
def register():
    '''
    Send the register.html page with the form.
    If the form posts and validates, create a new 
    user object and add it into the database.
    set_password is called with argument=1
      so that the account will be in limbo
      until the admin approves their account.
    '''
    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,
                    firstname=form.firstname.data,
                    lastname=form.lastname.data)
        user.set_password(form.password.data, 1)
        db.session.add(user)
        db.session.commit()
        flash('Account requested, await admin approval.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register',
                           form=form)
Exemplo n.º 27
0
def registration():
    form = RegistrationForm()

    if current_user.is_authenticated:
        return redirect(url_for('home.index'))

    if form.validate_on_submit():
        user = User(
            name=form.name.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data,
            admin=form.admin.data,
        )
        file = form.user_picture.data
        db.session.add(user)
        db.session.commit()
        if file:
            upload_user_picture(file, user)
        flash('Thanks for registering!', 'success')
        return redirect(url_for('auth.login'))
    return render_template('auth/registration.html', form=form, admin=True)
Exemplo n.º 28
0
def initial_setup():
    """Performs first time setup"""
    if check_setup():
        form = RegistrationForm()
        del form.admin  # Forces first user to be admin
        del form.reviewer  # Forces first user to be a reviewer
        del form.recaptcha
        if form.validate_on_submit():
            user = User(name=form.name.data,
                        organisation=form.organisation.data,
                        username=form.username.data,
                        email=form.email.data,
                        admin=True,
                        reviewer=True)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Admin user created successfully')
            return redirect(url_for('auth.login'))
        return render_template('auth/register.html',
                               title='Setup - Create Admin',
                               form=form)
    abort(403)
Exemplo n.º 29
0
def register():
    """
    Handle requests to the /register route
    Add an employee to the database through the registration form
    """
    form = RegistrationForm()
    if form.validate_on_submit():
        employee = Employee(email=form.email.data,
                            username=form.username.data,
                            first_name=form.first_name.data,
                            last_name=form.last_name.data,
                            password=form.password.data)

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

        # redirect to the login page
        return redirect(url_for('auth.login'))

    # load registration template
    return render_template('auth/register.html', form=form, title='Register')
Exemplo n.º 30
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    if not current_app.config['REGISTER_ALLOWED']:
        flash(
            "Sorry, we're not currently accepting new users. If you feel you've received this message in error, please contact an administrator.",
            "warning")
        return redirect(url_for('auth.login'))
    form = RegistrationForm()
    if form.validate_on_submit():
        validemail = User.validate_email(form.email.data)
        if not validemail:
            flash(
                "%s does not appear to be a valid, deliverable email address."
                % form.email.data, "danger")
            return redirect(url_for('auth.register'))
        user = User(email=validemail)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!', 'success')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
Exemplo n.º 31
0
def register():
    
    if current_user.is_authenticated:
        return redirect(url_for('home.profile'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User( email=form.email.data,
         username=form.username.data ,
         is_admin=form.is_admin.data,
         password=form.password.data)
        #user.set_password(form.password.data)
        # add user to the database
        db.session.add(user)
        db.session.commit()
        send_welcome_email(user)
        flash('You have successfully registered! Check your email.', category="your_error_argument")

        # redirect to the login page
        return redirect(url_for('auth.login'))

    # load registration template
    return render_template('auth/register.html', form=form, title='Register')
def register_user():
    if current_user.is_authenticated:
        flash('You are already logged in')
        return redirect(url_for('main.display_books'))

    form = RegistrationForm()

    if form.validate_on_submit():
        EmpDetails.create_user(empid=form.empid.data,
                               name=form.name.data,
                               email=form.email.data,
                               gender=form.gender.data,
                               login=form.login.data,
                               logout=form.logout.data,
                               password=form.password.data,
                               confirm=form.confirm.data,
                               hno=form.hno.data,
                               address=form.address.data,
                               pincode=form.pincode.data)
        flash('Registration Successful')
        return redirect(url_for('authentication.do_the_login'))

    return render_template('registration.html', form=form, count=0)
Exemplo n.º 33
0
def register(
):  #data pre-checks are done in forms.py, so the form can check the inputs for invalidity and inform the user of the invalidity before the page can be submitted
    if current_user.is_authenticated:  #if the user is already logged in
        flash(_('You are already a registered user'))
        return redirect(url_for(
            'main.index'))  #redirects to homepage IF user is authenticated
    form = RegistrationForm(
    )  #if user not logged in, form is set to an instance of RegistrationForm class
    if form.validate_on_submit():  #if the user submitted the form
        user = User(
            username=form.username.data.lower(),
            email=form.email.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data
        )  # assigns 'user' the data (username and email) that was submitted to the form by the user
        user.set_password(
            form.password.data
        )  # uses the password given in the registration form, assigns it to the user variable
        db.session.add(
            user)  #adds the user and their credentials to the data base
        admin = User.query.filter_by(
            username='******').first()  #admin follows each user that registers
        admin.follow(user)
        msg = Message(author=admin,
                      recipient=user,
                      body=current_app.config['NEW_USER_MESSAGE'])
        db.session.add(msg)
        db.session.commit()  #applys changes to the data base
        flash(_('Congratulations, You are now a registered user!')
              )  #print's confirmation message to user
        return redirect(
            url_for('auth.login')
        )  #redirects user to login page after registration is complete

    return render_template(
        'auth/register.html', title=_('Register'), form=form
    )  #colored 'form' contains all the user's form data, 'form' can be accessed by 'register.html' to print data to the page usually using the "." operator
Exemplo n.º 34
0
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        user_email = form.email.data.lower().strip()
        user_password = form.password.data

        # Check if user is already registered
        user = User.query.filter_by(email=user_email).first()
        if user:
            # Attempt to log the user in
            if user.verify_password(user_password):
                login_user(user)
                return redirect(
                    request.args.get('next') or url_for('main.index'))
            flash('Invalid username or password')
            return redirect(url_for('main.index'))

        # Register the user
        user = User(email=form.email.data.lower().strip(),
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        default_notebook = Notebook(title='Default', author_id=user.id)
        db.session.add(default_notebook)
        db.session.commit()
        user.default_notebook = default_notebook.id
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email,
                   'Confirm Your Account',
                   'auth/email/confirm',
                   user=user,
                   token=token)
        flash('A confirmation email has been sent.')
        return redirect(url_for('main.index'))
    return redirect(url_for('main.index'))
Exemplo n.º 35
0
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        # Register an existing guest user # TODO: What about a registered user visiting the registration form?
        if current_user.is_authenticated:
            current_user.username = form.username.data
            current_user.email = form.email.data
            current_user.password = form.password.data
            current_user.follow(current_user)
            current_user.save()

            send_confirmation_email()

            return redirect(url_for('dashboard.dashboard'))
        # Register a new user
        else:
            user = User(
                email=form.email.data,
                username=form.username.data,
                password=form.password.data,
            ).save()
            user.follow(user)
            login_user(user.seen())

            # Flask-Principal: Create an Identity object and signal that the identity has changed,
            # which triggers on_identify_changed() and on_identify_loaded(). Identity() takes a unique ID.
            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(user.id))

            return redirect(url_for('dashboard.dashboard'))

    return render_template(
        'auth/register.html',
        title="Register",
        form=form,
    )
Exemplo n.º 36
0
def register():
    # This is where we register users.
    # In the original version of the Microblog application, the user is just registered and the user
    # is redirected to the login page.
    # Using Activeconnect requires that we register the user with Activeconnect, then render
    # a page with information that allows them to register their mobile device with Activeconnect.
    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)

        # Register the user with Activeconnect.
        manager = get_management_api()
        add_user_result = manager.add_user(user.active_connect_id)

        if add_user_result == ManagementAPIResult.success:
            # We don't add the user to our database until they have been registered with Activeconnect.
            db.session.add(user)
            db.session.commit()
            flash(_('Congratulations, you are now a registered user!'))
            # Now redirect to the device registration page.
            return redirect(url_for('auth.register_device', user_id=user.id))
        else:
            # We failed to register the user so just show the page again.
            if add_user_result == ManagementAPIResult.user_exists:
                # User already exists
                flash('User already exists')
            else:
                # User failed
                flash('Failed to add user')
            return redirect(url_for('auth.register'))

    return render_template('auth/register.html',
                           title=_('Register'),
                           form=form,
                           no_status_checks=True)
Exemplo n.º 37
0
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        user_email = form.email.data.lower().strip()
        user_password = form.password.data

        # Check if user is already registered
        user = User.query.filter_by(email=user_email).first()
        if user:
            # Attempt to log the user in
            if user.verify_password(user_password):
                login_user(user)
                return redirect(request.args.get('next') or url_for('main.index'))
            flash('Invalid username or password')
            return redirect(url_for('main.index'))

        # Register the user
        user = User(
            email=form.email.data.lower().strip(),
            password=form.password.data)
        db.session.add(user)
        db.session.commit()
        default_notebook = Notebook(
            title='Default', author_id=user.id)
        db.session.add(default_notebook)
        db.session.commit()
        user.default_notebook = default_notebook.id
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(
            user.email, 'Confirm Your Account',
            'auth/email/confirm', user=user, token=token)
        flash('A confirmation email has been sent.')
        return redirect(url_for('main.index'))
    return redirect(url_for('main.index'))
Exemplo n.º 38
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)

        if User.query.filter_by(
                username=form.username.data).first() is not None:
            flash(
                "Someone with the username {} already exists! Try another name"
                .format(user.username))
            return render_template('auth/register.html',
                                   title='Register',
                                   form=form)

        user.set_password(form.password.data)
        db.session.add(user)  #pylint: disable=E1101
        db.session.commit()  #pylint: disable=E1101
        current_app.logger.info("New user {} has been added!".format(
            user.username))
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
Exemplo n.º 39
0
def register():
    form = RegistrationForm()
    print 'the code text is %s' % session.get('code_text', 'not exist!')
    if form.validate_on_submit():
        print 'yes'
        username = form.username.data
        print 'the user is %s'% username
        print 'the session is %s'%session['code_text']
        if get_user(username):
            flash(lazy_gettext('账号已注册!'))
            return render_template('register.html', title=_('注册'), form=form)
        if 'code_text' in session and session['code_text'] != form.verification_code.data.lower():
            flash(lazy_gettext('验证码错误,请刷新重填!'))
            return render_template('register.html', title=_('注册'), form=form)
        user = User(email=form.email.data, name=form.username.data, password=form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('auth.login'))
        except:
            db.session.rollback()
            flash(_('注册失败!'))
            return render_template('register.html', title=_('注册'), form=form)
    return render_template('register.html', title=_('注册'), form=form)
Exemplo n.º 40
0
def register():
    if current_user.is_authenticated:
        flash("You are already logged in!", "warning")
        return redirect(url_for("posts.home"))

    form = RegistrationForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        hashed_password = bcrypt.generate_password_hash(password).decode(
            'utf-8')

        new_user = User(username=username,
                        email=email,
                        password=hashed_password)

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

        flash("Cool, you're done,{}".format(username), "success")
        print(username)
        return redirect(url_for('auth.login'))
    return render_template('register.html', reg_form=form)
Exemplo n.º 41
0
def register():
    # if current_user.is_authenticated:
    #     return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # # добавляем текущий email в базу emails для проверки
        # redis_store.sadd('emails', form.email.data)
        # добавляем данные текущего пользователя
        id = 0 if redis_store.get('counter') == None else int(
            redis_store.get('counter'))
        redis_store.hset(id, 'username', form.username.data)
        #redis_store.hset(id, 'email', form.email.data)
        redis_store.hset(id, 'password_hash',
                         generate_password_hash(form.password.data))
        redis_store.hset(id, 'operating_mode', 'test')
        redis_store.hset(id, 'role', 'user')
        # добавляем пользователя в список пользователей сайта
        redis_store.hset('site_users', id, id)
        flash(
            Markup('<strong>' + form.username.data +
                   '</strong> успешно зарегистрирован!'))
        redis_store.set('counter', id + 1)
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Exemplo n.º 42
0
from flask import render_template, redirect, request, url_for, flash