示例#1
0
文件: controllers.py 项目: LukV/idnet
def signup():

    form = SignupForm(request.form)

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

        if not username:
            username = email.split('@')[0]

        user = User(username, email)
        user.password = password
        user.password_hash
        user.role = Role.USER
        user.status = Status.ACTIVE
        db.session.add(user)
        db.session.commit()

        flash(gettext('You can now login.'))
        return redirect(url_for('auth.login'))

    return render_template('auth/signup.html',
                           title=gettext('Sign up'),
                           form=form)
示例#2
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        email = form.email.data
        name = form.username.data
        password = form.password.data
        user = User(email=email, username=name)
        user.generate_password(password)
        try:
            db.session.add(user)
            db.session.commit()
            # 发邮件
            send_email(user.email,
                       user=user,
                       token=user.generate_confirmation_token())
            flash("注册成功")
            return redirect(url_for('auth.login'))
        except Exception as e:
            print(e)
            flash("注册失败")
            db.session.rollback()
    else:
        if request.method == "POST":
            flash("注册失败")
    return render_template('auth/signup.html', form=form)
示例#3
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = SignupForm()
    if form.validate_on_submit():
        user = auth_services.load_user(id=form.email.data)
        if user:
            return redirect(
                url_for(
                    "auth.signup",
                    homepage_message="Email address already exists. Try with different email.",
                )
            )
        auth_services.create_user(data=form.data)
        return redirect(
            url_for(
                "auth.login",
                homepage_message="Please login with newly created account.",
            )
        )
    return render_template(
        "auth/signup.html",
        title="Sign Up",
        form=form,
        homepage_message=request.args.get("homepage_message"),
    )
示例#4
0
def signup():

    form = SignupForm(request.form)

    if form.validate_on_submit():

        # get data from form
        password = form.password.data

        # hash user password
        pwhash = bcrypt.hashpw(password, bcrypt.gensalt(12))

        email = form.email.data

        # insert into DB
        user = User(form.first_name.data, form.last_name.data,
                    form.username.data, email, pwhash)

        # generate one time auth token
        auth_token = secrets.token_urlsafe(64)

        # insert user into DB
        db.session.add(user)
        db.session.commit()

        # create the pair of user id and auth token
        user_authentication = UserAuthentication(user.id, auth_token)

        # put the auth token in the DB
        db.session.add(user_authentication)
        db.session.commit()

        # get welcome/authentication email
        welcome_body = render_template("mail/welcome.html",
                                       auth_token=auth_token)

        # build message
        msg = Message("Welcom to the Auction Site",
                      sender=app.config['MAIL_USERNAME'],
                      recipients=[email],
                      html=welcome_body)

        # send it
        mail.send(msg)

        # set flash message in the session
        flashmsg = ("Thank you for creating your account, "
                    "to begin using it, you will have to authenticate it "
                    "using the email we have sent")

        flash(flashmsg)

        # redirect to home page
        return render_template("index.html")

    return render_template("auth/signup.html", page_title="Sign Up", form=form)
示例#5
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        if not User.query.filter_by(email=form.email.data).scalar():
            User(email=form.email.data, password=form.password.data).save()
            return redirect(url_for('auth.login'))
        else:
            form.errors['email'] = 'User already exists.'
            return render_template('auth/signup.html', form=form)
    return render_template('auth/signup.html', form=form)
示例#6
0
def signup():
    form = SignupForm()
    if(form.validate_on_submit()):
        flash("Check your inbox")
        user = User(username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()

        # qui dobbiamo autenticare l'utente ...

    return render_template('signup.html', form=form)
示例#7
0
def signup():
    form = SignupForm()
    if(form.validate_on_submit()):
        flash("Check your inbox")
        user = User(username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user, True)
        send_mail(user.email, "Confirm your email", "mails/email_confirm", user=user, token=user.generate_confirmation_token())

    return render_template('signup.html', form=form)
示例#8
0
def signup():
    # If sign in form is submitted
    form = SignupForm(request.form)
    # Verify the sign in form
    if form.validate_on_submit():
        user = User(name=form.name.data,
                    email=form.email.data,
                    password=generate_password_hash(form.password.data))
        s = db.session()
        s.add(user)
        s.commit()
        return redirect(url_for('auth.signin'))
    return render_template("auth/signup.html", form=form)
示例#9
0
def signup():
  # If sign in form is submitted
  form = SignupForm(request.form)
  # Verify the sign in form
  if form.validate_on_submit():
    user = User(name=form.name.data,
                email=form.email.data,
                password=generate_password_hash(form.password.data))
    s = db.session()
    s.add(user)
    s.commit()
    return redirect(url_for('auth.signin'))
  return render_template("auth/signup.html", form=form)
示例#10
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = SignupForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congrats, you are signed up!')
        return redirect(url_for('auth.login'))
    return render_template('auth/signup.html', title='Signup', form=form)
示例#11
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        encrypted_pwd = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user_id = db.add_user({
            'username': form.username.data,
            'password': str(encrypted_pwd),
            'email': form.email.data
        })
        user = User(form.username.data, str(encrypted_pwd), user_id,
                    form.email.data)
        login_user(user, remember=True)
        session['userInstance'] = user.toDict()
        return redirect(url_for('user_profile_blueprint.get_additional_info'))
    return render_template('auth/signup.html', title="Sign in", form=form)
示例#12
0
def process_signup():
    current_app.logger.info(f"New Sign Up attempt: {request.form['first_name']} - {request.form['last_name']} - {request.form['email']}")
    if current_app.config['DEBUG']:
        form = SignupForm()
        if form.validate_on_submit():
            user = User()
            form.populate_obj(user)
            user.set_password(form.password.data)
            user.active = True
            db.session.add(user)
            db.session.commit()
            flash('Welcome to Web Serialist.com!', 'success')
            return redirect(url_for('main.index'))
        return redirect(url_for('auth.login'))
    flash('We are not accepting new users at the moment. Thank you for your interest!', 'danger')
    return redirect(url_for('main.index'))
示例#13
0
def signup():
    form = SignupForm()

    if request.method == 'POST':
        if not form.validate_on_submit():
            return render_template('/auth/signup.html', form=form), 406
        user = User(username=form.username.data,
                    name=form.name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()

        return "sign in the user and redirect to Home"  # TODO

    elif request.method == 'GET':
        return render_template('/auth/signup.html', form=form)
示例#14
0
def signup():
    form = SignupForm()

    if request.method == 'POST':
        if not form.validate_on_submit():
            return render_template('/auth/signup.html', form=form), 406
        user = User(username=form.username.data,
                    name=form.name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()

        return "sign in the user and redirect to Home"  # TODO

    elif request.method == 'GET':
        return render_template('/auth/signup.html', form=form)
示例#15
0
文件: routes.py 项目: psv-git/labs
def sign_up():
    signup_form = SignupForm()
    if signup_form.validate_on_submit():
        user_name = signup_form.user_name_field.data
        user_email = signup_form.user_email_field.data
        user_password = signup_form.user_password_field.data
        if user_name and user_email and user_password:
            User.create(db_manager, user_name, user_email, user_password)
        return redirect("/signin_page")

    page_template = "auth/signup_page.html"
    page_data = {"page_name": "signup_page", "page_title": "Sign Up page"}
    return render_template(
        page_template,
        page_data=page_data,
        signup_form=signup_form,
    )
示例#16
0
def signup():
    if current_user.is_authenticated:
        return redirect(
            url_for('main.home'))  #TODO this should redirect to /home

    form = SignupForm()

    #returns true if request method is POST, GET if false
    if form.validate_on_submit():

        user = User(username=form.username.data)
        user.set_password(form.password.data)
        db.session.add(user)  # ignore these errors
        db.session.commit()
        flash('Successfully registered!')
        return redirect(url_for('auth.login'))

    return render_template('auth/signup.html', title='Sign up', form=form)