Ejemplo n.º 1
0
def register_page():
    reg_form = RegistrationForm(request.form)

    if request.method == "POST":
        if reg_form.validate() is False:
            return render_template('register.html',
                                   reg_form=reg_form)
        else:
            new_user = User(
                reg_form.first_name.data,
                reg_form.last_name.data,
                reg_form.username.data,
                reg_form.email.data,
                reg_form.password.data
            )
            db.session.add(new_user)
            db.session.commit()
            gc.collect()
            session['logged_in'] = True
            session['username'] = new_user.username
            flash('Thank you for registering!')
            return redirect(url_for('dashboard'))

    elif request.method == "GET":
        return render_template('register.html',
                               reg_form=reg_form)
Ejemplo n.º 2
0
def register():
	data = MultiDict(mapping=request.json)	
	inputs = RegistrationForm(data, csrf_enabled=False)
	
	if not inputs.validate():
		return transform(300, message="Invalid inputs")
	else:
		firstName = data.get('first_name')
		lastName = data.get('last_name')
		email = data.get('email')
		password = data.get('password')

		user = User(email, password, firstName, lastName)
		auth = AuthToken()

		user.tokens.append(auth)

		try:
			db.session.add(user)
			# db.session.add(auth)

			db.session.commit()
		except IntegrityError as e:
			return jsonify({"error": "email already taken"})

		response = auth.__repr__()
		response.update({
			'user_id': user.id,
			'first_name': user.first_name,
			'last_name': user.last_name
		})

		return jsonify(response)
Ejemplo n.º 3
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']

            user = User.objects.create_user(email, #email is username
                                            email, #email
                                            password)
            user.first_name = first_name
            user.last_name = last_name
            user.save()

            up = UserProfile(user=user)
            up.save()

            #request.session['next'] = '/'

            return authenticate(request, email, password)
    else:
        form = RegistrationForm()
    
    return render_to_response("login.html", {
            'form': form,
        },
        context_instance = RequestContext(request)
    )
Ejemplo n.º 4
0
def register():

    form = RegistrationForm(request.form)
    print form.validate()
    print form.errors
    if request.method == 'POST' and form.validate():
        user = User(form.username.data, form.email.data,
            form.password.data)
        session.add(user)
        try:
            session.commit()
        except IntegrityError as error:
            flash("Registration is unsucessful. A user with the same username or email address is already in use.")
            print error
            session.rollback()
            return render_template(
                'register.html',
                title="Register",
                form=form
            )
        flash("Registration is successful.")
        return redirect(url_for('login'))
    return render_template(
        'register.html',
        title="Register",
        form=form
        )
Ejemplo n.º 5
0
def registration():
    form = RegistrationForm()
    if form.validate_on_submit():
        if form.password.data != form.repeat_password.data:
            flash('passwords are not equal')
            return render_template('registration.html',
                                   title='Sign Up',
                                   form=form)
        user = User.query.filter_by(login=form.login.data).first()
        if user is not None:
            flash('user with this login already exists')
            return render_template('registration.html',
                                   title='Sign Up',
                                   form=form)
        if User.query.filter_by(email=form.email.data).first() is not None:
            flash('user with this e-mail already exists')
            return render_template('registration.html',
                                   title='Sign Up',
                                   form=form)

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

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

        return redirect(url_for('index'))
    return render_template('registration.html',
                           title='Sign Up',
                           form=form)
Ejemplo n.º 6
0
Archivo: auth.py Proyecto: icoz/pysymo
def register():
    if app.config['REGISTRATION_ENABLED'] and app.config['AUTH_TYPE'] == 'plain':
        reg_form = RegistrationForm()
        login_form = LoginForm()

        if reg_form.validate_on_submit():
            user = UserPlain(username=reg_form.username.data,
                             password=reg_form.password.data,
                             email=reg_form.email.data)
            # save user to db
            user_id, save_error = user.save()
            if user_id:
                # try to login
                if login_user(user):
                    flash(gettext('Logged in successfully.'), 'success')
                    return redirect(url_for('search'))
                else:
                    flash(gettext('Unable to log you in.'), 'warning')
                    return redirect(url_for('home'))
            else:
                flash(save_error, 'warning')
                return redirect(url_for('register'))
        else:
            flash_form_errors(reg_form)
            return render_template('register.html', reg_form=reg_form, login_form=login_form)
    else:
        return redirect(url_for('home'))
Ejemplo n.º 7
0
 def post(self):
     if g.user is not None and g.user.is_authenticated:
         return redirect(url_for('IndexView:get_0'))
     form = RegistrationForm(request.form)
     if form.validate_on_submit():
         form.save()
         login_user(form.user, True)
         return redirect(url_for('IndexView:get_0'))
     return render_template('registration.html', title='Sign In', form=form)
Ejemplo n.º 8
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        db = get_db()
        db.do_register(form.username.data, form.lastname.data,
                       form.firstname.data, form.email.data,
                       form.password.data, form.is_director.data)
        flash("Thanks for registering!")
        return redirect('/')
    return render_template('register.html', form=form)
Ejemplo n.º 9
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(form.username.data, form.email.data,
                    form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(u'感谢您的注册')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Ejemplo n.º 10
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User()
        form.populate_obj(user)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('/index'))
    return render_template('register.html', title = 'Register', form = form)
Ejemplo n.º 11
0
 def create(self):
     if current_user.is_authenticated():
         return self.redirect('UserEvents:index')
     form = RegistrationForm()
     if form.validate_on_submit():
         user = User.create(**form.data)
         login_user(user=user, remember=True)
         self.flash_success('Thank you for registering!')
         return self.redirect('UserEvents:index')
     return self.render('user/new.html', form=form)
Ejemplo n.º 12
0
def register():
    Form = RegistrationForm()
    if Form.validate_on_submit():
        user = User(email=Form.email.data, username=Form.username.data,
                    password=Form.password.data, nickname=Form.nickname.data)
        db.session.add(user)
        db.session.commit()
        flash('You can login Now !')
        return redirect(url_for('index'))
    return render_template('register.html', form=Form)
Ejemplo n.º 13
0
def add_monkey():
    form = RegistrationForm()
    if form.validate_on_submit():
        monkey = Monkey()
        form.populate_obj(monkey)
        monkey.add_friend(monkey)
        db.session.add(monkey)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('addMonkey.html', title='Add Monkey', form=form)
Ejemplo n.º 14
0
 def update(self, id_):
     user = User.get_or_abort(id_)
     if not user == current_user:
         pass
     form = RegistrationForm(obj=user)
     if form.validate_on_submit():
         user.update(**form.data)
         self.flash_success('Changes have been saved!')
         return self.redirect('User:get', id_=user.id)
     return self.render('user/edit.html', user=user, form=form)
Ejemplo n.º 15
0
def registration():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = RegistrationForm(request.form)
    if request.method == "POST" and form.validate():
        return registrate(form.username.data,
                          form.passwd.data,
                          form.email.data)
    return render_template('registration.html',
        title = 'Sign Up',
        form = form)
Ejemplo n.º 16
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 17
0
def register(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            new_user = User()
            new_user.username = form.cleaned_data["username"]
            new_user.set_password(form.cleaned_data["password"])
            new_user.email = form.cleaned_data["email"]
            new_user.save()
            return HttpResponseRedirect("/thanks")
    else:
        form = RegistrationForm()
    return render(request, "app/register.html", {"form": form})
def signup():
    """Render website's sign up page."""
    form = RegistrationForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            email       = request.form['email'].strip()
            password    = request.form['password'].strip()
            
            user = User(email=email, password=password)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('signin'))
    return render_template('signup.html', form=form)
Ejemplo n.º 19
0
 def test_register_form_mobile_number_missing(self):
     form_data = {
         'username': '******',
         'password1': '1234',
         'mobile_number': '',
         'email': '*****@*****.**',
         'alias': '',
         'gender': '',
         'year_of_birth': '1989',
         'identity': '',
         'tos': True
     }
     form = RegistrationForm(data=form_data)
     self.assertEqual(form.is_valid(), True)
Ejemplo n.º 20
0
 def test_register_form_email_incorrect(self):
     form_data = {
         'username': '******',
         'password1': '1234',
         'mobile_number': '0712341113',
         'email': 'an',
         'alias': '',
         'gender': '',
         'year_of_birth': '1989',
         'identity' : '',
         'tos': True
     }
     form = RegistrationForm(data=form_data)
     self.assertEqual(form.is_valid(), False)
Ejemplo n.º 21
0
def sign_up():
    r_form = RegistrationForm(request.form)
    user_details = get_user_details()

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

    return render_template('sign_up.html', r_form=r_form, username=user_details[1], email=user_details[2])
Ejemplo n.º 22
0
    def register_view(self):
        form = RegistrationForm(request.form)
        if helpers.validate_form_on_submit(form):
            user = User()

            form.populate_obj(user)

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

            login.login_user(user)
            return redirect(url_for('.index'))
        link = '<p>Already have an account? <a href="' + url_for('.login_view') + '">Click here to log in.</a></p>'
        self._template_args['form'] = form
        self._template_args['link'] = link
        return super(MyAdminIndexView, self).index()
Ejemplo n.º 23
0
def signup():
    error = None
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(
            username=form.username.data, 
            email=form.email.data,
            avatar=form.avatar.data,
            password=form.password.data
            )
        db.session.add(user)
        db.session.commit()
        referer = request.headers.get("Referer")
        flash('Thanks for registering')
        return redirect(referer or url_for('home.show_places'))
    return render_template('signup.html', form=form, error=error)
Ejemplo n.º 24
0
 def registration(self):
     form = RegistrationForm(data=request.get_json(force=True))
     if form.validate():
         user = User(
             username=form.username.data,
             email=form.email.data,
             password=bcrypt.generate_password_hash(form.password.data)
         )
         try:
             db.session.add(user)
             db.session.commit()
             return '', 201
         except SQLAlchemyError as e:
             # TODO: loging exeption e
             db.session.rollback()
             return return_response(500, jsonify(error='Произошлка ошибка во время запроса.'))
     return return_response(404, jsonify(error='Не вверно введены данные.'))
Ejemplo n.º 25
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        if not User.objects.filter(username=form.username.data):
            user = User(name=form.name.data,
                        username=form.username.data,
                        email=form.email.data,
                        service='local')
            user.set_password(form.password.data)
            user.authenticated = True
            user.save()
            login_user(user)
            flash("You successfully registered.")
            return redirect(url_for('views.index'))
        else:
            flash("That username is already taken.")
    return render_template('register.html', form=form, session=session)
Ejemplo n.º 26
0
def signup():
    error = None
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Users(
            username=form.username.data,
            password=bcrypt.generate_password_hash(form.password.data)
            )
        try:
            db.session.add(user)
            db.session.commit()
            login_user(user)
            flash("You have just signup up congrats!", "success")
            return redirect(url_for("hello"))
        except:
            flash("That username already exists", "danger")
            return redirect(url_for("signup"))
    return render_template("signup.html", form=form, error=error)
Ejemplo n.º 27
0
def get_registrationform(request):
    if(request.method=='POST'):
        form=RegistrationForm(request.POST)
        if form.is_valid():
            username=form.cleaned_data['username']
            email=form.cleaned_data['email']
            hotel=form.cleaned_data['hotel']
            location=form.cleaned_data['location']
            password1=form.cleaned_data['password1']
            password2=form.cleaned_data['password2']
            if password1==password2:
                u=User.objects.create_superuser(username,email,password1)
                r=Restaurant(name=hotel,location=location,user=u)
                r.save()
                return HttpResponseRedirect("/restaurants/lists/")
    else:
        form=RegistrationForm()

    return render(request,'registration/registration.html',{'form':form},)
Ejemplo n.º 28
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        if Admin.query.all() == None:
            role = 'superadmin'
        else:
            role = 'admin'
        user = Admin(name=form.name.data,
                     email=form.email.data,
                     phone_number=form.phone_number.data,
                     role=role)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for { form.name.data }!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", form=form)
Ejemplo n.º 29
0
def register():
    #    admin = Role.query.filter_by(name='admin').first()
    if current_user.role != 'admin':
        return redirect(url_for('accessdenied'))
#    if current_user.is_authenticated:
#        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        #        role = Role.query.filter_by(name=form.role.data).first()
        user = User(username=form.username.data,
                    email=form.email.data,
                    role=form.role.data)
        #        user.role.append(Role(name=form.role.data)) #not sure what to do here
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you have registered a user!')
        return redirect(url_for('registersuccess'))
    return render_template('registerWTF.html', title='Register', form=form)
def create_account():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    print("DEBUG: Form valid", form.validate())

    if form.validate_on_submit():
        conf_code = randint(1000, 9999)
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    admin=False,
                    cardtype=form.cardtype.data,
                    address=form.address.data,
                    email=form.email.data,
                    subscribed=form.subscribed.data,
                    active=False,
                    email_val=conf_code,
                    last_four=form.card_num.data %
                    10000 if form.card_num.data else None)
        if (form.card_num.data):
            user.set_card_num(form.card_num.data)
        if (form.card_exp.data):
            user.set_card_exp(form.card_exp.data)
        user.set_password(form.password.data)
        db.session.add(user)
        msg = Message("Thank you for registering!",
                      sender="*****@*****.**",
                      recipients=[form.email.data])
        msg.body = "Thank you for registering for an account with our online bookstore! Your code to verify and activate your account is: {}".format(
            conf_code)
        db.session.commit()
        mail.send(msg)
        if session.get('orderId'):
            order = Order.query.filter_by(id=session.get('orderId')).first()
            order.user_id = user.id
            db.session.commit()

        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('create_account.html',
                           title='create_user',
                           form=form)
Ejemplo n.º 31
0
def register():
    try:
        form = RegistrationForm(request.form)
        
        if request.method == "POST" and form.validate():
            username = form.username.data
            email = form.email.data
            password = sha256_crypt.encrypt((str(form.password.data)))
            c,conn = connection()
            
            x = c.execute("SELECT * FROM users WHERE username = (%s)",
                          [(thwart(username))])
            if int(x) > 0 :
                flash("That username is already taken, please choose another")
                return render_template('register/register.html', form=form)
            else:
                 c.execute("INSERT INTO users (username, password, email, tracking) VALUES (%s, %s, %s, %s)",
                          (thwart(username), thwart(password), \
                          thwart(email), thwart("/introduction-to-python-programming/")))
                 conn.commit()
                 flash("Thanks for registering!")
                 c.close()
                 conn.close()
                 gc.collect()
                 session['logged_in'] = True
                 session['username'] = username

                 return redirect("/")

        return render_template("register/register.html", form=form)
                
    except Exception as e:
        return(str(e))
    # form = RegisterForm()
    # if request.method == 'POST' and form.validate():
        
    #     print form.username.data,form.email.data,form.password.data
        
    #     print 'success'

    #     return render_template('register/register_complete.html')
    # return render_template('register/register.html', form=form)
Ejemplo n.º 32
0
def register():
    flash_result = ''
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password_2fa=form.password_2fa.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash_result = 'success'
        flash(flash_result)
        flash('Congratulations, you are now a registered user!, please log in')
        return redirect(url_for('login'))
    else:
        flash_result = 'failure'
        flash(flash_result)
        return render_template('register.html', title='Register', form=form)
Ejemplo n.º 33
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        customer = Customer(email=form.email.data,
                            phone=form.phone.data,
                            fname=form.fname.data,
                            lname=form.lname.data)
        customer.set_password(form.password.data)

        send_email(
            'Registration Complete', [form.email.data],
            render_template("register_email.html", fname=form.fname.data))

        db.session.add(customer)
        db.session.commit()
        flash('Congratulations, you are now registered!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 34
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Users(username=form.username.data,
                     mobile=form.mobile.data,
                     comments=form.password.data,
                     cash=10000)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(
            'Congratulations, you are now a registered user!<br>Please Log In.',
            "success")
        return redirect(url_for('login'))

    form.submit.label.text = 'Register'
    print(f"register:  This is 6 - calling register.html")
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 35
0
def users():
    if current_user.role == 'admin':
        user = Users.query.all()
        form = RegistrationForm()
        if form.validate_on_submit():
            user = Users(username=form.username.data,
                         phone_number=form.phone_number.data,
                         role=form.role.data,
                         cash=0)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Пользователь добавлен')
            return redirect(url_for('users'))
        return render_template('users.html',
                               title='Register',
                               user=user,
                               form=form)
    else:
        return redirect(url_for('index'))
Ejemplo n.º 36
0
def register():

    if current_user.is_authenticated:

        return redirect(url_for('index'))

    form = RegistrationForm()

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

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

        flash("You've registered! Please Sign In")

        return redirect(url_for('login'))

    return render_template('register.html', title="Register", form=form)
Ejemplo n.º 37
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('login'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Korisnik(ime=form.ime.data,
                        prezime=form.prezime.data,
                        adresa_ptt=form.adresa_ptt.data,
                        adresa_mesto=form.adresa_mesto.data,
                        adresa_ulica_broj=form.adresa_ulica_broj.data,
                        korisnik_email=form.korisnik_email.data,
                        id_korisnik_tip=form.id_korisnik_tip.data,
                        korisnik_login=form.korisnik_login.data,
                        korisnik_pass=form.korisnik_pass.data)
        user.set_password(form.korisnik_pass.data)
        db.session.add(user)
        db.session.commit()
        flash('Bravo, upravo ste postali registrovani korisnik!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 38
0
def user_create():
    if current_user.is_authenticated:
        return redirect(url_for('images_view'))
    form = RegistrationForm()
    if form.validate_on_submit():

        pswd = generate_password_hash(form.password.data)

        putItem_User(form.username.data,
            pswd,
            email = form.email.data,
            images=[]
             )

        flash('You are now registered')
        user = User()
        user.id = form.username.data
        login_user(user)
        return redirect(url_for('images_view'))
    return render_template('users/new.html', title='New User', form=form)
Ejemplo n.º 39
0
def register():
    # if current_user.is_authenticated: TODO - might want to delete this since only the webmaster can register new users
    #     return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        user = User(username=form.username.data,
                    email=form.email.data,
                    urole=form.urole.data,
                    access_level=WEBMASTER
                    if form.urole.data == 'WEBMASTER' else ADMIN,
                    password=hashed_pw)

        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 40
0
def register():
    """[summary]
    
    Returns:
        [type] -- [description]
    """
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        
        #save the model to the database
        db.session.add(user)
        db.session.commit()
        
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 41
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()

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

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

        login_user(user)

        flash('Now you\'re registred.')

        return redirect(url_for('index'))

    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 42
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

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

        dishes = Dishes.query.all()
        for dish in dishes:
            dishquantity = Quantity(quantity=0, dish=dish, customer=user)
            db.session.add(dishquantity)
        db.session.commit()

        flash('Congratulations, you are registered user!')
        return redirect(url_for('index'))

    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 43
0
def register():
    if current_user.is_authenticated:
        flash("You're already registered and logged in.")
        return redirect(url_for('index'))

    form = RegistrationForm()

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

        app.logger.info('[REGISTRATION] New user registered: (' +
                        str(user.id) + ') //')

        flash('Success! You are now a registered user.')
        return redirect(url_for('login'))

    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 44
0
def register():
    """
        Same process as login, but with added step of updating the user table in db
        Server-side validation implemented in forms.py class declaration
    """

    #checks if user is logged in, if they are - redirect to home page
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congrats! It\'s time to get hoppin!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 45
0
Archivo: routes.py Proyecto: BRZInc/idp
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    first_name=form.firstname.data,
                    last_name=form.lastname.data,
                    email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        flash("You've been successfully registered!")
        return redirect(url_for('login'))

    return render_template("register.html",
                           page_title="Registration",
                           form=form)
Ejemplo n.º 46
0
def register():
    """Render the registration page."""
    # To redirect authenticated/logged in user
    if current_user.is_authenticated and current_user.StecAdmin == True:
        return redirect(url_for('admin_dashboard'))
    elif current_user.is_authenticated:
        return redirect(url_for('dashboard'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Users(Name=form.name.data,
                     Username=form.username.data,
                     Email=form.email.data,
                     Confirmed=False)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        email_confirmation(user)
        flash('An email confirmation has been sent, check your email.')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 47
0
def register_page():
    session["loggedIn"] = False
    session["currentUser"] = ""
    session["access_level"] = ""
    session["accountName"] = ""
    form2 = RegistrationForm()
    if form2.validate_on_submit():
        #print("hello")
        account = str(form2.account.data)
        password = str(form2.password.data)
        if form2.validateAccountname(account)==0:
            error="Sorry the Account already exist!"
            flash(error)
            return render_template("register.html", form=form2, error=error)
        else:
            database.create_account(account)
            database.insert_into_users(account,'root',password,'3')
            success="Congrats! New User Created!"
            return render_template("register.html", form=form2, success=success)
    return render_template("register.html", form=form2,error="")
    def edit(self, request, event, registration, form=None):
        request.user.check_admin_of(event.committee)

        if form is None:
            form = RegistrationForm(event, instance=registration)

        return render(request, 'registration_edit.html', {
            'event': event,
            'registration': registration,
            'form': form
        })
Ejemplo n.º 49
0
def register():
    """
    Renders the HTML in 'templates/register.html' and upon submit...
    - Checks if the user is logged in, if so, redirects to the index page
    - Creates a user object from the data in the form. The RegistrationForm
        includes validator methods to ensure unique username and email.
    - Commits the new user to the database.
    - Redirects the client to the login page.
    """
    if current_user.is_authenticated:  # Redirect the user to the index page if the user is already logged in
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 50
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    firstname=form.firstname.data,
                    lastname=form.lastname.data,
                    gender=form.gender.data,
                    profession=form.profession.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        send_confirmation_email(user.email)
        flash('Congratulations, you are now a registered user!')
        flash(
            'Thanks for registering!  Please check your email to confirm your email address.',
            'success')
        return redirect(url_for('login'))
    return render_template('signUp.html', title='Register', form=form)
Ejemplo n.º 51
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()

    if form.is_submitted():
        print("Submitted Successfully!")
    if form.validate():
        print("Validated")
    print(form.errors)

    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('Awesome, you\'re all set up!')
        sleep(3)
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 52
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(username=form.username.data.lower(),
                    first_name=form.first_name.data.lower(),
                    last_name=form.last_name.data.lower(),
                    email=form.email.data.lower(),
                    current_status_id=default_status.id)

        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('success$You are now a registered user !')
        return redirect(url_for('login'))

    return render_template('register.html', form=form)
Ejemplo n.º 53
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('display'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password,
                    state=form.state.data,
                    age=form.age.data,
                    gender=form.gender.data,
                    education=form.education.data)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 54
0
def register():

    html = {}
    html['title'] = "Register"
    html['description'] = "Join us today"
    html['content'] = ""

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

    form = RegistrationForm()

    if form.validate_on_submit():
        user = NetUser(username=form.username.data, email=form.email.data)
        user.set_password(form.password1.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))

    return render_template('register_new.html', html=html, form=form)
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    username=form.username.data,
                    email=form.email.data
                    )
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        session['username'] = user.username
        flash('You need to scan the QR code below to complete registration')
        return redirect(url_for('two_factor_setup'))
    return render_template('register.html',
                           title='Register',
                           form=form
                           )
Ejemplo n.º 56
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    next = request.args.get('next')
    login_form = LoginForm()
    registration_form = RegistrationForm()
    if registration_form.validate_on_submit():
        user = User(username=registration_form.username.data,
                    email=registration_form.email.data.lower())
        user.set_password(registration_form.password.data)
        db.session.add(user)
        db.session.commit()

        login_user(user)

        return redirect(url_for('index'))
    return render_template('authenticate.html',
                           login_form=login_form,
                           registration_form=registration_form,
                           next=next)
Ejemplo n.º 57
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(name=re.sub(r'\s', '', form.name.data),
                    surname=re.sub(r'\s', '', form.surname.data),
                    patronymic=re.sub(r'\s', '', form.patronymic.data),
                    email=re.sub(r'\s', '', form.email.data),
                    position=form.position.data,
                    organization=form.organization.data,
                    materials='')
        user.set_password(form.password.data)
        email = Email(value=form.email.data)
        db.session.add(user)
        db.session.add(email)
        db.session.commit()
        flash('Вы зарегистрированы')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 58
0
Archivo: views.py Proyecto: danrr/SELP
def register():
    """Displays registration form and handles user creation """
    form = RegistrationForm()
    if form.validate_on_submit():
        old_user = User.query.filter_by(username=form.username.data).first()
        if old_user is not None:
            flash('User {user} already exists'.format(user=form.username.data), 'error')
            return redirect((url_for('register')))
        old_user = User.query.filter_by(email=form.email.data).first()
        if old_user is not None:
            flash('{email} already used'.format(email=form.email.data), 'error')
            return redirect((url_for('register')))
        user = User(username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Please login to your new account'.format(user=form.username.data), 'info')
        return redirect((url_for('login')))
    return render_template('register.html',
                           title='Register',
                           form=form)
Ejemplo n.º 59
0
def signup():
    g.signup_form = RegistrationForm()
    if g.signup_form.validate_on_submit():
        user = User(username=g.signup_form.username.data,
                    email=g.signup_form.email.data)
        user.set_password(g.signup_form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('index'))
    return render_template('index.html')
Ejemplo n.º 60
0
def register():
	if request.method == "GET":
		return render_template("register.html", registration_form = RegistrationForm(), referrer = request.referrer or url_for('index'))

	form = RegistrationForm(request.form)	
	if not form.validate():
		return render_template("register.html", registration_form = form, referrer = request.form["referrer"] or url_for('index'))

	user = User.query.filter_by(login = form.login.data).all()

	if user:
		form.login.errors.append(constants.ERROR_USER_ALREADY_REGISTERED.format(name = form.login.data))
		return render_template("register.html", registration_form = form, referrer = request.form["referrer"] or url_for('index'))

	user = User(login = form.login.data, password = form.password.data)
	db.session.add(user)
	db.session.commit()
	
	session["user"] = user.login

	flash(constants.FLASH_MESSAGE_USER_REGISTERED.format(name = form.login.data))	
	return redirect(request.form["referrer"] or url_for("index"))