예제 #1
0
def register():
    """
    This is the view for registering a user.
    """

    form = RegistrationForm()

    # if the current user is authenticated then redirected to the home page
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    if form.validate_on_submit():
        # encrypt the password using bcrypt
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        if form.picture.data:
            # the save_picture function from the utils module for saving the image in cropped size
            image_file = save_picture(form.picture.data)

        # setting the user with the data from the register form.
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password,
                    image_file=image_file)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created', 'sucess')
        return redirect(url_for('home'))
    return render_template('register.html', form=form)
예제 #2
0
    def __init__(self, email, password, confirmed, admin=False, confirmed_on=None):
        self.email = email
        self.password = bcrypt.generate_password_hash(password)
        self.registered_on = datetime.datetime.now()
        self.admin = admin
	self.confirmed = confirmed
	self.confirmed_on = confirmed_on
예제 #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('features.index'))

    form = RegistrationForm()
    if form.validate_on_submit():

        msg = Message('Thanks for Registering!',
                      sender='*****@*****.**',
                      recipients=[str(form.email.data)])
        msg.body = "Hi there! Thanks for registering to Cat Wiki!\n\nYour username is: " + str(
            form.username.data
        ) + "\n\nThank you for using our website, we hope you have an excellent day!"
        mail.send(msg)
        session['new_username'] = form.username.data

        hashed = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")

        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed)
        user.save()
        return redirect(url_for('users.tfa'))

    return render_template('register.html', title='Register', form=form)
예제 #4
0
def account():
    username_form = UpdateUsernameForm()
    password_form = UpdatePasswordForm()
    profile_pic_form = UpdateProfilePicForm()

    if password_form.validate_on_submit():
        hashed = bcrypt.generate_password_hash(
            password_form.new_password.data).decode("utf-8")

        msg = Message('Password Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your password has been updated! Please reply to this e-mail if you did not request this change."
        mail.send(msg)

        current_user.modify(password=hashed)
        current_user.save()

        return redirect(url_for('users.account'))

    if username_form.validate_on_submit():
        temp = User.objects(username=current_user.username).first()
        current_user.username = username_form.username.data

        msg = Message('Username Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your username has been updated!\nYour new username is: " + str(
            username_form.username.data)
        mail.send(msg)

        current_user.modify(username=username_form.username.data)
        current_user.save()

        return redirect(url_for('users.account'))

    if profile_pic_form.validate_on_submit():
        img = profile_pic_form.propic.data
        filename = secure_filename(img.filename)

        if current_user.profile_pic.get() is None:
            current_user.profile_pic.put(img.stream, content_type='images/png')
        else:
            current_user.profile_pic.replace(img.stream,
                                             content_type='images/png')
        current_user.save()

        return redirect(url_for('users.account'))

    image = images(current_user.username)

    return render_template("account.html",
                           title="Account",
                           username_form=username_form,
                           password_form=password_form,
                           profile_pic_form=profile_pic_form,
                           image=image)
예제 #5
0
파일: main.py 프로젝트: musemen/ImageRepo
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('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)
예제 #6
0
def render_registration_page():
    form = RegistrationForm()
    if form.validate_on_submit():
        print("sumitted", flush=True)
        username = form.username.data
        password = form.password.data
        user_type = form.usertype.data
        contact = form.contact.data
        credit_card = form.credit_card.data
        is_part_time = form.is_part_time.data
        postal_code = form.postal_code.data
        hashed_password = bcrypt.generate_password_hash(password).decode(
            'utf-8')

        # query = "INSERT INTO users(username, contact, card, password, usertype, isPartTime, postalcode) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}')" \
        #     .format(username, contact, credit_card, hashed_password, user_type, is_part_time, postal_code)
        # db.session.execute(query)
        # db.session.commit()

        user1 = Users(username=username,
                      usertype=user_type,
                      contact=contact,
                      card=credit_card,
                      postalcode=postal_code,
                      password=hashed_password)
        role = Role.query.filter_by(name=user_type).first()
        user1.roles.append(role)
        db.session.add(user1)

        #query = "SELECT * FROM role WHERE name = '{}'".format(user_type)
        #givenRole = db.session.execute(query).fetchone()
        #query = "INSERT INTO user_roles(contact, usertype) VALUES ('{}', '{}')".format(contact, user_type)
        #db.session.execute(query)
        db.session.commit()

        canparttime1 = CanPartTime(contact=contact, isparttime=is_part_time)
        db.session.add(canparttime1)
        db.session.commit()
        #query = "INSERT INTO users(username, contact, card, password, usertype, isPartTime, postalcode) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}')" \
        #    .format(username, contact, credit_card, hashed_password, user_type, is_part_time, postal_code)
        # print(query, flush=True)
        # db.session.execute(query)
        # print("done", flush=True)
        # db.session.commit()
        print("commited", flush=True)
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect("/login")
    print("rendered", flush=True)
    return render_template("registration.html",
                           title='Registration',
                           form=form)
예제 #7
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(first_name=form.first_name.data, last_name=form.last_name.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('home'))
    else :
        flash('Something went Wrong can,t submit form', 'danger')
    return redirect(url_for('home'))
예제 #8
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is invalid or expired token', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been reseted! You are now able to login',
              'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html', form=form)
예제 #9
0
def render_owner_profile_update():
    contact = current_user.contact
    petowner = Users.query.filter_by(contact=contact).first()
    if petowner:
        form = UserUpdateForm(obj=petowner)
        if request.method == 'POST' and form.validate_on_submit():
            profile = Users.query.filter_by(contact=contact).first()
            profile.username = form.username.data
            profile.password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            profile.card = form.credit_card.data
            profile.postalcode = form.postal_code.data
            db.session.commit()
            print("Owner profile has been updated", flush=True)
            return redirect(url_for('view.render_owner_profile'))
        return render_template("update.html",
                               form=form,
                               username=current_user.username + " owner")
예제 #10
0
def change_user_info():
    passwordform = ResetPasswordForm()
    if passwordform.validate_on_submit():
        if bcrypt.check_password_hash(current_user.password,
                                      passwordform.original_password.data):
            hashed_password = bcrypt.generate_password_hash(
                passwordform.password.data).decode('utf-8')
            current_user.password = hashed_password
            db.session.commit()
            flash('Reset password successful!', 'success')
            return redirect(url_for('main.home'))
        else:
            return redirect(url_for('main.home'))
            flash('Current password is not correct', 'warning')
    form = LoginForm()
    name = current_user.name
    user = User.query.filter_by(name=name).first()
    return render_template('/changeuserinfo.html', user_info=user, form=form)
예제 #11
0
def render_registration_page():
    form = RegistrationForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        user_type = form.usertype.data
        contact = form.contact.data
        credit_card = form.credit_card.data
        is_part_time = form.is_part_time.data
        postal_code = form.postal_code.data
        hashed_password = bcrypt.generate_password_hash(password).decode(
            'utf-8')

        # DON"T CHANGE THIS. linked to other flask librarys like login_manager
        user1 = Users(username=username,
                      usertype=user_type,
                      contact=contact,
                      card=credit_card,
                      postalcode=postal_code,
                      password=hashed_password)
        #roleQuery = "SELECT name FROM role WHERE name = '{}' LIMIT 1".format(user_type)
        # usage of ORM as it has hidden properties related to flask that allows us to verify roles and get current_user
        role = Role.query.filter_by(name=user_type).first()
        #role = db.session.execute(roleQuery).fetchall()
        user1.roles.append(role)
        db.session.add(user1)
        db.session.commit()
        if (user_type == 'caretaker'):
            salery = 0 if is_part_time else 3000
            canparttime1 = Canparttime(ccontact=contact,
                                       isparttime=is_part_time,
                                       avgrating=5.0,
                                       petday=0,
                                       salary=salery)
            db.session.add(canparttime1)
            db.session.commit()
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect("/login")
    return render_template("registration.html",
                           title='Registration',
                           form=form)
예제 #12
0
def render_owner_profile_update():
    contact = current_user.contact
    userQuery = "SELECT * FROM users WHERE contact = '{}';".format(contact)
    petowner = db.session.execute(userQuery).fetchall()
    if petowner:
        form = UserUpdateForm(obj=petowner)
        if request.method == 'POST' and form.validate_on_submit():
            update = """UPDATE users
                    SET username = '******', password = '******', card = '{}', postalcode = '{}'
                    WHERE contact = '{}';""".format(
                form.username.data,
                bcrypt.generate_password_hash(
                    form.password.data).decode('utf-8'), form.credit_card.data,
                form.postal_code.data, contact)
            db.session.execute(update)
            db.session.commit()
            return redirect(url_for('view.render_owner_profile'))
        return render_template("update.html",
                               form=form,
                               username=current_user.username)
예제 #13
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    try:
        if form.validate_on_submit():

            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(name=form.name.data,
                        password=hashed_password,
                        api_code=form.api_code.data)  #add new user, 要符合form
            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('main.login'))
    except:
        flash('Your account name already used!', 'warning')
    return render_template('register.html', title='Register', form=form)
예제 #14
0
파일: models.py 프로젝트: kimshangyup/gee
 def __init__(self, username, password, email):
     self.username = username
     self.password = bcrypt.generate_password_hash(password=password)
     self.email = email