示例#1
0
def register():
    """ This function for registering the user """
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        users = db.execute(
            "SELECT * FROM users WHERE username= :username OR email= :email", {
                "username": form.username.data,
                "email": form.email.data
            }).fetchall()
        if users:
            flash('username  or email taken  please choose  another one',
                  'danger')
        else:
            db.execute(
                'INSERT INTO users(username, email, password) values (:username, :email, :password)',
                {
                    "username": form.username.data,
                    "email": form.email.data,
                    "password": hashed_password
                })
            db.commit()
            flash(f'Account created  you can now log in', 'success')
            return redirect(url_for('login'))
    return render_template('register.html', form=form)
示例#2
0
def signup():

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

    isbn = request.args.get('next')
    form = RegistrationForm()
    if form.validate_on_submit() and request.method == 'POST':

        username = form.username.data
        email = form.email.data
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        #user = db.execute("INSERT INTO Users (username, email, password) VALUES (:username, :email, :password);", {'username':username, 'email': email, 'password' :hashed_password})
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        #---Needs Check
        login_user(user, remember=form.remember.data)
        session['logged_in'] = True
        session['username'] = username
        #session['user_img'] = db.execute("SELECT image_file FROM Users WHERE username=:username", {'username':username})
        #print(session['user_img'])
        if isbn:
            return redirect(url_for('books'))
        flash(f'Account successfully created for {form.username.data}!!',
              'success')
        return redirect(url_for('search'))

    return render_template('signup.html',
                           title='Sign Up',
                           form=form,
                           next=isbn)
示例#3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Application.query.filter_by(email=form.email.data).first()
        if user:
            blacklisted_user = ApplicationBlacklist.query.filter_by(
                application_id=user.id).first()
            if blacklisted_user:
                flash('The email entered has been blacklisted')
                return redirect(url_for('login'))

            if user.is_pending:
                flash(
                    'Your application still under review, Please try again later'
                )
                return redirect(url_for('login'))

        user2 = Application(name=form.name.data,
                            last_name=form.lastName.data,
                            email=form.email.data,
                            interest=form.interest.data,
                            credentials=form.credentials.data,
                            reference=form.reference.data)
        db.session.add(user2)
        db.session.commit()
        flash('Your application has been sent.', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
示例#4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(name=form.name.data,
                    email=form.email.data,
                    password=hashed_password,
                    classITA=form.classITA.data,
                    isRepr=form.isRepr.data)
        db.session.add(user)

        for subject in Subject.query.filter_by(classITA=user.classITA).all():
            user.subjects.append(subject)
            abs = Absence(student=user, subject=subject, abs=0.0, just=0)
            db.session.add(abs)

        db.session.flush()
        db.session.commit()
        flash('Sua conta foi criada! Agora você pode ingressar no sistema.',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Cadastro', form=form)
示例#5
0
def register():
    if session.get('user_name'):
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user_id = User.objects.count()
        user_id += 1
        first_name = form.first_name.data
        last_name = form.last_name.data
        email = form.email.data
        password = form.password.data
        user = User(first_name=first_name,
                    last_name=last_name,
                    user_id=user_id,
                    email=email)
        user.set_password(password)
        user.save()
        # save data to database
        flash("You are successfully Registered.", "Success")
        return redirect(url_for("index"))
        # return form.errors()
    return render_template("Register.html",
                           title="Register",
                           form=form,
                           Register=True)
示例#6
0
def account_delete():
    user = current_user.id
    account = Users.query.filter_by(id=user).first()
    posts = Posts.query.filter_by(user_id=user).all()
    logout_user()
    for post in posts:
        db.session.delete(post)
    db.session.delete(account)
    db.session.commit()
    return redirect(url_for('register'))

    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hash_pw=bcrypt.generate_password_hash(form.password.data)

        user=Users(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data, 
            password=hash_pw
            )

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

        return redirect(url_for('post'))
    return render_template('register.html', title='Register', form=form)
def register():
    # Check if user is already logged in
    if current_user.is_authenticated:
        return redirect(url_for('account'))
    form = RegistrationForm()
    # Check if a request is both a POST request and a valid request
    if form.validate_on_submit():
        username    = form.username.data
        email       = form.email.data
        first_name  = form.first_name.data
        last_name   = form.last_name.data
        password    = form.password.data
        gdpr_check  = form.gdpr_check.data

        # Create new instance of user
        user = User(username = username, email = email, first_name = first_name, last_name = last_name, gdpr_check = gdpr_check)
        # Hash password
        user.set_password(password)
        # Insert record to the DB
        user.save()
        flash(f'Welcome, we\'re glad to have you here {form.first_name.data}! Please login with your e-mail and password.', 'success')
        return redirect("/login")

    # Getting latest 5 recipes for footer
    footer_recipes = Recipe.objects[:5].order_by('-recipe_id')

    # Render html, giving its title, passing in the form and footer recipes
    return render_template("register.html", title = "Register", form = form, footer_recipes = footer_recipes)
示例#8
0
def register():
    #Redirects the user if the user has been authenticated
	if current_user.is_authenticated:
		return redirect(url_for('home'))

    #Initiliases the form to be passed over to the HTML
	form = RegistrationForm()
    #Addes the enteries and hashes the password for extra security
	if form.validate_on_submit():
		hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8')

		user = Users(
			first_name=form.first_name.data,
			last_name=form.last_name.data,
			username=form.username.data,
			email=form.email.data,
			password=hashed_pw
		)

		db.session.add(user)
		db.session.commit()
		flash('You have successfully registered! You can now login')
		return redirect(url_for('login'))

	return render_template('register.html', title='Register', form=form)
示例#9
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        # Shows one time message on web using success color
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('index'))
    return render_template('register.html', title='Register', form=form)
示例#10
0
def register():
    form = RegistrationForm()
    register_fields = [
        form.email, form.first_name, form.last_name, form.username,
        form.password, form.confirm_password
    ]
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data)
        user = User(email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    username=form.username.data,
                    password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('create_team'))
    else:
        print(form.errors)
        return render_template("register.html",
                               title="Register",
                               form=form,
                               fields=register_fields)
示例#11
0
def register():
    # Preventing logged in user from going to register route again
    if session.get('username'):
        return redirect(url_for('index'))

    form = RegistrationForm()

    # Validate_on_submit will automatically call teh validate_email method in Registration_form class and check if mail already exist  or not.
    if form.validate_on_submit():
        # getting total no. of documents in user collection
        user_id = User.objects.count()

        # incrementing th user id by 1 as user id needs to be unique
        user_id += 1

        email = form.email.data
        password = form.password.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        user = User(user_id=user_id,
                    email=email,
                    first_name=first_name,
                    last_name=last_name)
        user.set_password(password)  # Saving password after hashing
        user.save()
        flash("You are successfully registered!", "success")
        return redirect(url_for('index'))

    return render_template('register.html',
                           title="Register",
                           form=form,
                           register=True)
示例#12
0
def register():
    logged_in = False
    form      = RegistrationForm()  #form is an instance of the RegistrationForm class
    title     = "Register"

    if form.validate_on_submit():
        
        #get the ID for this new user who is registering
        lastUserId = User.objects.count() #get number of users already in database
        newUserId = lastUserId + 1

        #get the new user's credentials
        newUserFirst_name = form.first_name.data
        newUserLast_name  = form.last_name.data
        newUserEmail      = form.email.data
        newUserPassword   = form.password.data

        #create a new user object and save it to the database
        newUser   = User(user_id = newUserId, first_name = newUserFirst_name, 
                         last_name = newUserLast_name, email = newUserEmail)

        #hash password and assign it to the new user object
        newUser.hash_and_set_password( newUserPassword )

        #save the new user object to the database
        newUser.save()

        flash(f"{newUserFirst_name}, you are successfully registered! You can now login." , "success")

        return redirect("/index")
        
    return render_template("register.html", title=title, form=form, register=True, logged_in=logged_in)
示例#13
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(first_name=form.cleaned_data['first_name'],last_name=form.cleaned_data['last_name'],username=form.cleaned_data['username'],password=form.cleaned_data['password1'],email=form.cleaned_data['email'],last_login='******')
            return HttpResponseRedirect('/')
    form = RegistrationForm()
    variables = RequestContext(request, {'form': form})
    return render_to_response('registration/registration_form.html',variables)
示例#14
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data)
        user = Users(email=form.email.data, password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('post'))
    return render_template('register.html', title='Register', form=form)
示例#15
0
def addBio(request):
    variables = ""
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user_bio = form.cleaned_data['user_bio']
            cursor.execute('INSERT INTO THUser/user_description (null,'+user_bio+');')
            return HttpResponseRedirect('/')
        variables = RequestContext(request, {'form': form})
    return render_to_response('editBio.html',variables)
示例#16
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Success!! You have Created A New Account!!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
示例#17
0
def register():
	if current_user.is_authenticated:
		return redirect(url_for('home'))
	form = RegistrationForm()
	if form.validate_on_submit():
		hashed_pw = bcrypt.generate_password_hash(form.password.data.decode('utf-8'))
		user = Users(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, password=hashed_pw)
		db.session.add(user)
		db.session.commit()
		return redirect(url_for('post'))
	return render_template('register.html', title='Register', form=form)
示例#18
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('blank'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
示例#19
0
def register():
    if current_user.is_authenticated:
       return redirect('/index')
    my_form = RegistrationForm()
    if my_form.validate_on_submit():
       u = User(username=my_form.username.data,email=my_form.email.data)
       u.set_password(my_form.password.data)
       db.session.add(u)
       db.session.commit()
       flash("Congratulations you have Registered in successfully")
       return redirect(url_for('login'))
    return render_template('register.html',title = 'Register',form = my_form) 
示例#20
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Поздравляем, теперь вы зарегистрированный пользователь!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Регистрация', form=form)
示例#21
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('registration.html', title='Register', form=form)
示例#22
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('register.html', form=form)
示例#23
0
def api_register():
    form = RegistrationForm()
    user = User(username=form.username.data, email=form.email.data)
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.add(user)
        db.session.commit()
        return jsonify(user.to_dict())
    response = user.to_dict()
    response['errors'] = form.errors
    return jsonify(response), 401
示例#24
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hash_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        user = users(username=form.username.data, password=hash_pw)

        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))

    return render_template('register.html', title='Register', form=form)
示例#25
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been made. You can now Log In!', 'success')
        return redirect(url_for('login'))
    return render_template("register.html", form=form)
示例#26
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password).save()
        flash(f'Account created for {user.username}!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
示例#27
0
def registration():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    regform = RegistrationForm()
    if regform.validate_on_submit():
        user = Users(username=regform.username.data, email=regform.email.data)
        user.set_password(regform.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Поздравляем, вы прошли регистрацию')
        return redirect(url_for('login'))
    return render_template('registration.html',
                           title="Регистрация",
                           regform=regform)
示例#28
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("snake"))

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

        account = Account_details(login=form.login.data, password=hashed_pw)

        db.session.add(account)
        db.session.commit()
        return redirect(url_for("snake"))
    return render_template("register.html", title="Register", form=form)
示例#29
0
def register():
    form = RegistrationForm()
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    if form.validate_on_submit():

        user = Users(first_name=form.first_name.data,
                     last_name=form.last_name.data,
                     email=form.email.data)

        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
示例#30
0
def register():
    #If user logged in; redirect to home
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    #Sets up registration form
    form = RegistrationForm()
    if form.validate_on_submit():
	#hash password
        hashed_pw = bcrypt.generate_password_hash(form.password.data)
        user = User(username=form.username.data, email=form.email.data, password=hashed_pw)
	#adds user to database
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)
示例#31
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hash_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = Users(first_name=form.first_name.data,
                     last_name=form.last_name.data,
                     email=form.email.data,
                     password=hash_pw)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('home'))
    else:
        print(form.errors)
    return render_template('register.html', title='Register', form=form)
示例#32
0
def register():
	if(current_user.is_authenticated):
		return redirect(url_for('index'))

	form = RegistrationForm()
	if(form.validate_on_submit()):
		user = User(username=form.username.data, email=form.email.data)
		user.set_password(form.password.data)
		user.set_balance(0)
		db.session.add(user)
		db.session.commit()
		flash('Successfully registered!')
		return redirect(url_for('login'))

	return render_template('register.html', title='Register', form = form)
示例#33
0
文件: account.py 项目: jittat/adm2
def register(request):
    if request.method == 'POST':
        if 'cancel' in request.POST:
            return redirect_to_index(request)
        form = RegistrationForm(request.POST)

        if not settings.NAT_ID_VERIFICATION:
            form.disable_national_id_verification()

        if form.is_valid():
            email = form.cleaned_data['email']
            first_name=form.cleaned_data['first_name']
            last_name=form.cleaned_data['last_name']
            national_id=form.cleaned_data['national_id']

            result, error_field, applicant = (
                validate_email_and_national_id(email,
                                               national_id))

            if result:
                try:
                    applicant = form.get_applicant()
                    passwd = applicant.random_password()
                    applicant.save()
                except IntegrityError:
                    # somehow, it gets error

                    result, error_field, applicant = (
                        validate_email_and_national_id(email,
                                                       national_id))
                    return registration_error(error_field,
                                              applicant,
                                              email,
                                              national_id,
                                              first_name,
                                              last_name)
                
                registration = Registration(
                    applicant=applicant,
                    first_name=first_name,
                    last_name=last_name)
                registration.random_and_save()
                send_password_by_email(applicant, passwd)
                return render_to_response(
                    'application/registration/success.html',
                    {'email': form.cleaned_data['email'],
                     'step_name': "การลงทะเบียนเรียบร้อย" })
            else:
                if not applicant.has_logged_in:
                    return registration_error(error_field,
                                              applicant,
                                              email,
                                              national_id,
                                              first_name,
                                              last_name)

                # e-mail or national id has been registered and logged in
                from django.forms.util import ErrorList
                from commons.utils import admin_email

                if error_field == 'email':
                    dup_obj = u'อีเมล์'
                else:
                    dup_obj = u'รหัสประจำตัวประชาชน'

                form._errors['__all__'] = ErrorList([
u"""%(dup_obj)sนี้ถูกลงทะเบียนและถูกใช้แล้ว ถ้าอีเมล์นี้เป็นของคุณจริงและยังไม่เคยลงทะเบียน
กรุณาติดต่อผู้ดูแลระบบทางอีเมล์ <a href="mailto:%(email)s">%(email)s</a> หรือทางเว็บบอร์ด
อาจมีผู้ไม่ประสงค์ดีนำอีเมล์คุณไปใช้""" % {'dup_obj': dup_obj,
                                 'email': admin_email()}])
                
    else:
        form = RegistrationForm()
    return render_to_response('application/registration/register.html',
                              { 'form': form },
                              context_instance=RequestContext(request))