コード例 #1
0
ファイル: views.py プロジェクト: priyamshah112/ether-app
def index():
    form = Form()
    if request.method == 'POST' and form.validate():
        email = request.form['email']
        # Check that email does not already exist (not a great query, but works)
        if not db.session.query(Subscriber).filter(
                Subscriber.email == email).count():
            subscriber = Subscriber(email=email, confirmed=False)
            db.session.add(subscriber)
            db.session.commit()

            token = generate_confirmation_token(subscriber.email)
            confirm_url = url_for('confirm_email', token=token, _external=True)
            html = render_template('emails/subscribers.html',
                                   confirm_url=confirm_url,
                                   token_time_limit=TOKEN_EXPIRATION_MINUTES)
            subject = "Please confirm your subscription to analyseether.com"
            send_email(subscriber.email, subject, html)

            message = Markup("Thank you for subscribing, we have sent you \
                                              a verification email.")
            flash(message)

            return redirect(url_for('index', _anchor='signUpForm'))

        else:  # The subscriber email exists in the database
            subscriber = Subscriber.query.filter_by(email=email).first_or_404()

            if subscriber.confirmed:  # the subscriber has confirmed his email
                message_email_already_verified = Markup(
                    'This email has already been verified')
                flash(message_email_already_verified)
            else:  # resent the confirmation email
                token = generate_confirmation_token(subscriber.email)
                confirm_url = url_for('confirm_email',
                                      token=token,
                                      _external=True)
                html = render_template(
                    'emails/subscribers.html',
                    confirm_url=confirm_url,
                    token_time_limit=TOKEN_EXPIRATION_MINUTES)
                subject = "Please confirm your subscription to analyseether.com"
                send_email(subscriber.email, subject, html)

                message_token_resent = Markup(
                    'Email exists, we have resent you \
                                              a verification email.')
                flash(message_token_resent)
            return redirect(url_for('index', _anchor='signUpForm'))
    elif request.method == 'POST' and not form.validate():
        for field, errors in form.errors.items():
            for error in errors:
                message_validation_error = Markup(error)
                flash(message_validation_error)
        return redirect(url_for('index', _anchor='signUpForm'))

    return render_template('index.html', form=form)
コード例 #2
0
ファイル: views.py プロジェクト: pathcl/runbook
def signup():
    """
    User Sign up page: Very basic email + password
    sign up form that will also login users.
    """
    # Data is used throughout for the jinja2 templates
    data = {"active": "signup", "loggedin": False}  # Sets the current page  # Don't show the logout link

    # Define the SignupForm
    form = SignupForm(request.form)
    # Validate and then create userdata
    if request.method == "POST":
        if form.validate():
            # Take form data
            email = form.email.data
            password = form.password.data
            company = form.company.data
            contact = form.contact.data
            userdata = {"username": email, "email": email, "password": password, "company": company, "contact": contact}

            # Create user
            user = User()
            user.config = app.config
            result = user.createUser(userdata, g.rdb_conn)
            # Check results for success or failure
            if result == "exists":
                flash("User already exists.", "danger")
            elif result is not False:
                try:
                    stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " User Signup", 1)
                except:
                    pass
                print("/signup - New user created")
                cdata = cookies.genCdata(result, app.config["SECRET_KEY"])
                data["loggedin"] = True
                flash("You are signed up.", "success")

                # Generate confirmation token
                generate_confirmation_token(email, result, time.time())

                # Build response
                resp = make_response(redirect(url_for("member.dashboard_page")))
                timeout = int(time.time()) + int(app.config["COOKIE_TIMEOUT"])
                # Set the cookie secure as best as possible
                resp.set_cookie("loggedin", cdata, expires=timeout, httponly=True)
                return resp
        else:
            stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " False User Signup", 1)
            print("/signup - False user creation")
            flash("Form is not valid.", "danger")

    # Return Signup Page
    return render_template("user/signup.html", data=data, form=form)
コード例 #3
0
ファイル: views.py プロジェクト: jmjuanico/likereader
def update():
    error = None
    form = UpdateForm()
    next = get_redirect_target()
    next = retain_before_auth_page(next)
    if request.method == 'POST':
        if request.form['submit'] == 'cancel':
            return redirect_back('index')
        else:
            if form.validate_on_submit():
                user = User.query.filter_by(username=form.username.data).first()
                if user:
                    # creates and sends the token which contains the secret keys
                    token = generate_confirmation_token(user.email)
                    confirm_update_url = url_for('confirm_password', token=token, _external=True)
                    update_notification(user, confirm_update_url)

                    flash('A confirmation email has been sent.', 'success')
                    return redirect_back('index')
                else:
                    flash('Invalid username.', 'danger')
                    return render_template('update.html', form=form, error=error, next=next)
            else:
                flash('Invalid username.', 'danger')
                return render_template('update.html', form=form, error=error, next=next)
    else:
        return render_template('update.html', form=form, error=error, next=next)
コード例 #4
0
def register():
    form = register_form()
    user = Logindb.query.filter_by(email=form.email.data).first()
    if request.method == "POST":
        if user:
            error = 'User already registered'
            return render_template('register.html', form=form, error=error)
        else:
            userid = random.randint(10000000, 99999999)
            u_id = Logindb.query.filter_by(userid=userid).first()
        if u_id:
            userid = random.randint(10000000, 99999999)
        else:
            user = Logindb(userid, form.email.data, form.password.data)
            db.session.add(user)
            db.session.commit()
            token = generate_confirmation_token(user.email)
            confirm_url = url_for('confirm_email',
                                  confirmcode=token,
                                  _external=True)
            html = render_template('activate.html', confirm_url=confirm_url)
            subject = "Please confirm your email"
            sendmail(user.email, subject, html)

            login_user(user)

            return redirect(url_for('profile'))
    return render_template('register.html', form=form)
コード例 #5
0
ファイル: views.py プロジェクト: votopkov/questionnaire
def sign_up():
    if 'remember_me' in session:
        return redirect(url_for("index"))
    form = SignUpForm()
    if form.validate_on_submit():
        u_nickname = User.query.filter_by \
            (nickname=form.nickname.data).first()
        u_mail = User.query.filter_by \
            (email=form.email.data).first()
        if u_nickname is not None:
            flash('user with such nickname exist', 'danger')
        elif  u_mail is not None:
            flash('user with such email exist', 'danger')
        else:
            user = User(nickname=form.nickname.data,
                        password=form.password.data,
                        email=form.email.data)
            if user:
                db.session.add(user)
                db.session.commit()
                token = generate_confirmation_token(user.email)
                confirm_url = url_for('confirm_email',
                                      token=token,
                                      _external=True)
                html = render_template('activation.html',
                                       confirm_url=confirm_url)
                subject = "Please confirm your email"
                send_email(user.email, subject, html)
                flash('You are signed up! Pleaese confirm your mail,'
                      ' confirmation email was sent to you email')
            else:
                flash('Wrong enter', 'danger')
    return render_template('sign_up.html',
                           title = 'Sign up',
                           form = form)
コード例 #6
0
ファイル: controllers.py プロジェクト: samkariu/beyonic_auth
def register():
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        name = request.form['name']
        phone_number = request.form['phone_number']
        password = request.form['password']
        if User.query.filter(User.username==username).first():
            flash('User already exists. Please log in.')
        if User.query.filter(User.email==email).first():
            flash('Email already exists. Please log in.')
        if User.query.filter(User.phone_number==phone_number).first():
            flash('Phone number already exists.')
        pw_hash = bcrypt.generate_password_hash(request.form['password'])
        user = User(username=username, pw_hash=pw_hash,email=email,name=name,
            phone_number=phone_number)
        db.session.add(user)
        db.session.commit()

        token = generate_confirmation_token(user.email)
        confirm_url = url_for('users.confirm_email', token=token, _external=True)
        html = render_template('users/email_activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        flash('User successfully registered. Please log in.')
        return redirect(url_for('users.login'))
    return render_template('users/register.html')
コード例 #7
0
ファイル: views.py プロジェクト: GavinatorK/dynamozappa
def register():
    """
    Handle requests to the /register route
    Add an employee to the database through the registration form
    """
    form = RegistrationForm()
    if form.validate_on_submit():
        employee = {"email":form.email.data,
                            "username":form.username.data,
                            "first_name":form.first_name.data,
                            "last_name":form.last_name.data,
                            "password":form.password.data,
                            "confirmed":False,
                            "confirmed_on":"?"}

        # add employee to the database
        db.createItem("Employee",employee)
        if db.getItem("Employee", {"username":form.username.data}):

            flash('You have successfully registered! You may now login.')

        # redirect to the login page
        token = generate_confirmation_token(form.email.data)
        confirm_url = url_for('auth.confirm_email', token=token, _external=True)
        html = render_template('auth/activate.html', confirm_url=confirm_url)
        print html
        subject = "Please confirm your email"
        send_email(form.email.data, subject, html)
        flash('A confirmation email has been sent via email.', 'success')
        return redirect(url_for('auth.login'))

    # load registration template
    return render_template('auth/register.html', form=form, title='Register')
コード例 #8
0
def resend_confirmation():
    token = generate_confirmation_token(current_user.email)
    confirm_url = url_for('confirm_email', confirmcode=token, _external=True)
    html = render_template('activate.html', confirm_url=confirm_url)
    subject = "Please confirm your email"
    send_email(current_user.email, subject, html)
    flash('A new confirmation email has been sent.', 'success')
    return redirect(url_for('unconfirmed'))
コード例 #9
0
def resend_confirmation(subject):
    # Generate a new token
    token = generate_confirmation_token(current_user.email)

    # Generate the temporary url the user will be sent to
    confirm_url = url_for("user.confirm_email", token=token, _external=True)

    html = render_template("user/activate.html", confirm_url=confirm_url)

    subject = "Please confirm your email"

    send_email(current_user.email, subject)


# message, port, smltp_server, login, password, sender_email, receiver_email, subject
コード例 #10
0
def signup():
    mailform = MailingListForm()
    if mailform.validate_on_submit():
        if MailingList.query.filter_by(email=mailform.email.data).first():
            flash('Email %s is already on the list.' %
                  (mailform.email.data), 'danger')
            return redirect(url_for('signup'))            
        contact = MailingList(email=mailform.email.data)
        db.session.add(contact)
        db.session.commit()
        token = generate_confirmation_token(mailform.email.data)
        confirmation_url = url_for('confirm_mailinglist', token=token, _external=True)
        msg = Message('Thanks for registering', recipients=[mailform.email.data])
        msg.body = "You're almost on the Blue Line Novelties mailing list. Use this link to verify your address:   %s" % (confirmation_url)
        mail.send(msg)
        flash('A confirmation email has been sent to %s, please follow the instructions therein to complete the registration process.' %
              (mailform.email.data), 'info')
        return redirect(url_for('products'))
    return render_template('signup.html', mailinglistform=mailform)
コード例 #11
0
def register():

	if request.method == 'POST' and g.form.validate_on_submit() != False:
		user = User(username=g.form.username.data, email=g.form.email.data, password=g.form.password.data, confirmed=False)
		print 'done'
		db.session.add(user)
		db.session.commit()
		token = generate_confirmation_token(user.email)
		confirm_url = url_for('confirm_email', token=token, _external=True)
		html = render_template('user/activate.html', confirm_url=confirm_url)
		subject = "Please confirm your email"
		send_email(user.email, subject, html)
		flash('You have signed up successfully! Check your mail box for a confirmation email.', 'success')
		return redirect(url_for('index'))
	elif request.method == 'POST' and g.form.validate_on_submit() == False:
		flash(u'Looks like you type something wrong, please try again!', 'warning')
		return render_template('index.html', reg_errors=g.form.errors)
	print 'startup fail'
	return render_template('index.html')
コード例 #12
0
ファイル: views.py プロジェクト: tjcunliffe/runbook
def signup():
    '''
    User Sign up page: Very basic email + password
    sign up form that will also login users.
    '''
    # Data is used throughout for the jinja2 templates
    data = {
        'active': "signup",  # Sets the current page
        'loggedin': False  # Don't show the logout link
    }

    # Define the SignupForm
    form = SignupForm(request.form)
    # Validate and then create userdata
    if request.method == "POST":
        if form.validate():
            # Take form data
            email = form.email.data
            password = form.password.data
            company = form.company.data
            contact = form.contact.data
            userdata = {
                'username': email,
                'email': email,
                'password': password,
                'company': company,
                'contact': contact
            }

            # Create user
            user = User()
            user.config = app.config
            result = user.createUser(userdata, g.rdb_conn)
            # Check results for success or failure
            if result == "exists":
                flash('User already exists.', 'danger')
            elif result is not False:
                try:
                    stathat.ez_count(
                        app.config['STATHAT_EZ_KEY'],
                        app.config['ENVNAME'] + ' User Signup', 1)
                except:
                    pass
                print("/signup - New user created")
                cdata = cookies.genCdata(result, app.config['SECRET_KEY'])
                data['loggedin'] = True
                flash('You are signed up.', 'success')

                # Generate confirmation token
                generate_confirmation_token(email, result, time.time())

                # Build response
                resp = make_response(redirect(url_for('member.dashboard_page')))
                timeout = int(time.time()) + int(app.config['COOKIE_TIMEOUT'])
                # Set the cookie secure as best as possible
                resp.set_cookie(
                    'loggedin', cdata, expires=timeout, httponly=True)
                return resp
        else:
            stathat.ez_count(
                app.config['STATHAT_EZ_KEY'],
                app.config['ENVNAME'] + ' False User Signup', 1)
            print("/signup - False user creation")
            flash('Form is not valid.', 'danger')

    # Return Signup Page
    return render_template('user/signup.html', data=data, form=form)