コード例 #1
0
def registration():
    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')  # password encryption
        if form.picture.data:
            pic_name = save_pic(form.picture.data, 'registration')
        else:
            pic_name = 'default_pic.png'
        user = User(name=form.username.data,
                    password=hashed_password,
                    email=form.email.data,
                    image_file=pic_name,
                    role='author')
        db.session.add(user)
        db.session.commit()
        flash(
            f'Account Successfully created for {form.username.data} successfully.',
            'success')
        return redirect(url_for('home'))
    return render_template('registration.html',
                           parameter=parameters,
                           title='Registration Form',
                           show_navbar=False,
                           form=form)
コード例 #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)
        db.session.commit()
        flash('Kayıt olduğunuz için teşekkür ederiz...')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
コード例 #3
0
ファイル: app.py プロジェクト: hruturaj/NewsScrapper-Python
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()
        flash("Thanks for the registration!")
        return redirect(url_for('login'))
    return render_template('registration.html', 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(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)
コード例 #5
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()
        flash('New user has been added.')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #6
0
ファイル: routes.py プロジェクト: skysinghthakur/mySystem
def register():
    if (current_user.is_authenticated):
        return redirect(url_for('login'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.email.data}!', 'success')
        return redirect(url_for('login'))
    return render_template('signup.html', title='Register', form=form)
コード例 #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('lessons'))
    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()
        flash("Account created for " + str(form.username.data), 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #8
0
def register():
    if current_user.is_authenticated:
        if current_user.type == "user":
            return redirect(url_for('user'))
        if current_user.type == "admin":
            return redirect(url_for('admin'))

    form = RegistrationForm()
    option = request.form.get("option")

    if request.form.get('submit', False) == "Register":
        if form.validate_on_submit():

            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            name = request.form['username']
            phone = request.form['phone']
            email = request.form['email']
            password = request.form['password']
            address = request.form['address']

            if option == "user":
                print("impl", flush=True)
                my_data = User(name, email, hashed_password, phone, address)

                db.session.add(my_data)
                flash("Registeration Successfull! Pls login to access page",
                      "text-success")

                db.session.commit()

            elif option == "admin":
                my_data = Admin(name, email, hashed_password, phone, address)
                try:
                    db.session.add(my_data)
                    db.session.commit()

                except:
                    if form.validate_on_submit():
                        flash(
                            "Registeration Successfull! Pls login to access page",
                            "text-success")
            else:
                pass

    else:
        pass

    return render_template('register.html', title='Register', form=form)
コード例 #9
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(fname=form.fname.data,
                    lname=form.lname.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('dashboard'))
    return render_template("register.html", form=form)
コード例 #10
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"
        )
        new_user = User(
            firstname=form.first_name.data,
            lastname=form.last_name.data,
            email=form.email.data,
            password=hashed_password,
        )
        db.session.add(new_user)
        db.session.commit()
        flash("Account succesfully created.", "success")
        return redirect(url_for("login"))
    return render_template("register.html", form=form)
コード例 #11
0
def index():
    form = RegistrationForm()
    if form.validate_on_submit():
        print(form.lv_options.data)
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            login_user(user, remember=True)
            if form.lv_options.data == 'Others':
                #register from another field
                pass
            else:
                #add current user & product combination to the relation table
                item = Item.query.filter_by(sku=form.lv_options.data,
                                            country=form.region.data).first()
                item.subscribed_users.append(current_user)
                db.session.commit()
                #send email
                msg = Message("Welcome back, successfully subscribed",
                              sender=("Updater24", "*****@*****.**"),
                              recipients=[form.email.data])
                mail.send(msg)
        else:
            if form.lv_options.data == 'Others':
                #register from another field
                pass
            else:
                user = User(email=form.email.data)
                db.session.add(user)
                db.session.commit()
                login_user(user)
                item = Item.query.filter_by(sku=form.lv_options.data,
                                            country=form.region.data).first()
                item.subscribed_users.append(current_user)
                db.session.commit()
                #send email
                msg = Message("Welcome! Successfully subscribed",
                              sender=("Updater24", "*****@*****.**"),
                              recipients=[form.email.data])
                mail.send(msg)
        return 'subscribed successfully!'
    print(form.errors)
    return render_template('index.html', form=form)
コード例 #12
0
    def post(self,request):
        form = RegistrationForm(request.POST)
        if form.is_valid():
            try:
                user = User()
                user.name = form.cleaned_data['name']
                user.last_name = form.cleaned_data['last_name']


                token = str(form.cleaned_data['token'])
                user.email = signing.loads(token[2:])['email']

                user.username = form.cleaned_data['username']
                user.set_password(form.cleaned_data['password'])

                if token.startswith('cm'):
                    user.role = 1
                    user.save()
                    return HttpResponseRedirect('/clinicLocation_list/?username=%s' % user.username)
                elif token.startswith('wp'):
                    user.role = 2
                    user.save()
                    return HttpResponseRedirect('/login')
                elif token.startswith('di'):
                    user.role = 3
                    user.save()
                    return HttpResponseRedirect('/login')
                elif token.startswith('ad'):
                    user.role = 4
                    user.save()
                    return HttpResponseRedirect('/adminView')
                else:
                    return HttpResponseRedirect('/register')

            except IntegrityError as e:
                print (e.args)
                if "UNIQUE constraint" in e.args[0]:
                    form = RegistrationForm
                    return render(request, 'project/register.html', {'form': form, 'error':'Invalid username or token!'})


        return HttpResponseRedirect('/login')
コード例 #13
0
def register():

    # if user is already logged in, send them to the homepage
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    # create registration form object
    form = RegistrationForm()

    # if registration form has been validly submitted
    if form.validate_on_submit():

        # hash the password that the user ended
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        db = get_db()

        # set up db cursor
        mycursor = db.cursor()

        # run the query to add the user to the database
        query = """INSERT INTO Users (userName, userFirstName, userLastName, userStreetAddress, userCity, userState, userZip, userPhoneNumber, userEmail, userPW) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
        mycursor.execute(
            query, (form.username.data, form.firstName.data,
                    form.lastName.data, form.userStreet.data,
                    form.userCity.data, form.userState.data, form.userZip.data,
                    form.userPhone.data, form.email.data, hashed_pw))

        # commit the query
        db.commit()

        mycursor.close()

        # display success message if user successfully registered
        flash(f'Your account has been created. Please login.', 'success')

        # render account page
        return redirect(url_for('login'))

    # if no data has been submitted, display the registration page
    return render_template('register.html', title='Register', form=form)
コード例 #14
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data.lower(),
                    fname=form.fname.data,
                    lname=form.lname.data,
                    nickname=form.nickname.data,
                    role="user",
                    active=1,
                    rewardsid=form.rewardsid.data,
                    password=form.password.data)
        if form.check_email(user.email):
            db.session.add(user)
            db.session.commit()
            flash('Thanks for registering! Now you can login!')
            return redirect(url_for('main.login'))
        else:
            flash('The email address you chose is already in our system.')
            return redirect(url_for('main.register'))
    return render_template('register.html', form=form)
コード例 #15
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            print('form has been validated')
            if User.query.filter_by(email=form.email.data).count() == 0:

                AI = int(form.immatriculation_year.data)
                NCS = int(form.num_of_ects.data)
                MP = float(form.weighted_mean.data)
                score = calc_score(AI, NCS, MP)

                new_user = User(
                    email=form.email.data,
                    password=form.password.data,
                    matricola=form.matricola.data,
                    immatriculation_year=form.immatriculation_year.data,
                    num_of_ects=form.num_of_ects.data,
                    weighted_mean=form.weighted_mean.data,
                    score=score,
                    has_already_done_erasmus=form.previous_erasmus.data,
                    choice1=form.choice1.data,
                    choice2=form.choice2.data,
                    choice3=form.choice3.data,
                )
                db.session.add(new_user)
                db.session.commit()
            else:
                flash('Utente già registrato con questo indirizzo email',
                      category='warning')
                return redirect(url_for('login'))

            return redirect(url_for('login'))

    return render_template('register.html', title='Register', form=form)
コード例 #16
0
ファイル: app.py プロジェクト: Ana9-tech/Project
def signup():
    form = RegistrationForm()
    if request.method == "POST":
        password = form.password.data
        password_hash = generate_password_hash(password)

        user = User(names=form.names.data,
                    email=form.email.data,
                    password_hash=password_hash)

        db.session.add(user)
        db.session.commit()
        flash("registration was successful", "success")
        return redirect(url_for('login'))

    return render_template('signup.html', form=form)
コード例 #17
0
ファイル: routes.py プロジェクト: SrishtiSinghD/WeCode2
def register():
    """ 
    This will rediirect a logged-in user to home-page when they click the register button on our site
    Here, 'current_user.is_authenticated' is a boolean variable.
    """
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    """
    We will create an instance of a registration form everytime to send to the application.
    """
    form = RegistrationForm()
    """
    Now, we need to validate the data we are getting from the user, so we will first validate data and then post template.
    We will also flash an alert message to user on invalid entry using the 'flash' class in Flask.
    """
    if form.validate_on_submit():
        """ 
        So, after the form is validated, firstly we will save the password entered by the user in the database , in hashed form.
        Here, we will be first passing the password entered by the user to the 'generate_password_hash()' function in bcrypt class
        it will return hashed password in form of bytes.
        To convert the hashed password in form of string we will use the 'decode.('utf-8') method .
        Syntax:
            variable_storing_hashed_password = bcrypt.generate_password_hash('password_string').decode('utf-8')
        """

        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        """ After storing the hashed password we will create a user instance """
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        """ Next, we are going to add this user to our database """
        db.session.add(user)
        """ In order to actually show those changes in our database, we use the commit command """
        db.session.commit()

        flash(
            'Your account has been successfully created! You are now able to log in',
            'success')
        #flash(f'Account created for {form.username.data} !', 'success')
        """
        (f) string is available from Python 3.6 as a replacement for (format) to access variables in strings.
        Users below Python 3.6 should use format specifiers.
        flash('Message','Bootstrap_Style_for_Message')
        Like here our Message == 'Account created for {form.username.data}!'
        Bootstrap_Style_for_Message == 'success'
        These flashed messages are a one-time alert, they disappear when you reload the same window.
        """
        """
        CODE FOR TRIAL:-
        Now we need to redirect the user to the home page after successful form completion
        For this we import redirect class from Flask

        return redirect(url_for('home')) 
        """
        """
        Now we need to redirect the user to the home page after successful form completion
        For this we import redirect class from Flask
        """
        return redirect(url_for('login'))

    #Here, we will pass this form to our HTML Template
    return render_template('register.html', title='Register', form=form)