Esempio n. 1
0
def register():
    from app.app import db
    """Register Form"""
    form = MyRegisterForm()
    if form.validate_on_submit():
        exist = db.session.query(User).filter_by(email=form.email.data).first()
        if exist is not None:
            return render_template(
                'register.html',
                form=form,
                error='There is already an account with this email address')
        new_user = User(username=form.username.data,
                        email=form.email.data,
                        password=form.password.data,
                        active=True,
                        confirmed=False)
        new_user.roles.append(fetch_user_role())

        token = generate_confirmation_token(new_user.email)
        confirm_url = url_for('routes.confirm_email',
                              token=token,
                              _external=True)
        html = render_template('mail_confirmation_account.html',
                               confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(new_user.email, subject, html)

        flash('A confirmation email has been sent via email.', 'success')

        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('routes.login'))
    return render_template('register.html', form=form)
Esempio n. 2
0
def token_mail():
    mail = current_user.useremail
    token = generate_confirmation_token(mail)
    confirm_url = url_for('confirm_email', token=token, _external=True)
    html = render_template('meldingen.html', confirm_url=confirm_url)
    send_mail(mail, html) 
    flash('En bekreftelseslink har blitt sendt via mail', 'success')
Esempio n. 3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegisterForm()
    if form.validate_on_submit():
        extension = '.' + form.photo.data.filename.rsplit('.', 1)[1]
        user = User(username=form.username.data,
                    email=form.email.data,
                    description=form.description.data,
                    extension=extension)
        user.set_password(form.password.data)
        photo = request.files[form.photo.name]
        photo.save(
            os.path.join(app.static_folder, app.config['PHOTO_FOLDER'],
                         secure_filename(form.username.data + extension)))
        db.session.add(user)
        db.session.commit()
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('confirm_email', token=token, _external=True)
        send_email(subject="Please confirm your email",
                   sender=app.config['MAIL_DEFAULT_SENDER'],
                   recipients=[user.email],
                   html_body=render_template('activate.html',
                                             confirm_url=confirm_url))
        flash('A confirmation email has been sent via email.', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 4
0
def register():
    error = None
    form = RegisterForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_user = User(user_name=form.user_name.data,
                            email=form.email.data,
                            password=bcrypt.generate_password_hash(
                                form.password.data),
                            confirmed=False)
            try:
                db.session.add(new_user)
                db.session.commit()
                token = generate_confirmation_token(new_user.email)
                confirm_url = url_for('users.confirm_email',
                                      token=token,
                                      _external=True)
                html = render_template('activate.html',
                                       confirm_url=confirm_url)
                subject = "Please confirm your email"
                send_email(new_user.email, subject, html)
                flash('A confirmation email has been sent via email.')
                return redirect(url_for('users.login'))

            except IntegrityError:
                error = "That username and/or email alread exists."
                return render_template('register.html', form=form, error=error)
    return render_template('register.html', form=form)
Esempio n. 5
0
def admin_create_user():
    from app.app import db
    form = UserForm()
    if form.validate_on_submit():
        password = os.urandom(24)
        exist = db.session.query(User).filter_by(email=form.email.data).first()
        if exist is not None:
            return render_template(
                'admin/create_user.html',
                form=form,
                error='There is already an account with this email address')
        new_user = User(username=form.username.data,
                        email=form.email.data,
                        password=password,
                        active=True)
        for role in form.my_roles.data:
            if role == 'user':
                new_user.roles.append(fetch_user_role())
            elif role == 'admin':
                new_user.roles.append(fetch_admin_role())
        db.session.add(new_user)
        email = form.email.data
        # We ill send an email to the user asking him to reset his password
        token = generate_confirmation_token(email)
        confirm_url = url_for('routes.reset_password',
                              token=token,
                              _external=True)
        html = render_template('mail_reset_password.html',
                               confirm_url=confirm_url)
        subject = "Leosac select password"
        send_email(email, subject, html)

        db.session.commit()
        return redirect(url_for('routes.dashboard'))
    return render_template('admin/create_user.html', form=form)
Esempio n. 6
0
def register():
    """Provides registering for user"""

    # if register form is submitted
    form = RegisterForm(request.form)

    # verify the register form
    if form.validate_on_submit():
        # create user and add to database
        user = User(
            username=form.username.data,
            password=generate_password_hash(form.password.data),
            email=form.email.data
        )
        db.session.add(user)
        db.session.commit()

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

        #login_user(user)

        # everything okay so far
        flash(gettext(u'Confirmation email has been sent'), 'info')
        return redirect(url_for('users.login'))

    return render_template('users/register.html', form=form)
Esempio n. 7
0
def register():
    if current_user.is_authenticated:
        flash('You are logged-in already')
        return redirect(url_for('index'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    cnf=False)
        user.set_password(form.password.data)
        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('emails/confirm_email_email.html',
                               confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        login_user(user)
        flash('A confirmation email has been sent to your inbox.', 'success')
        return redirect(url_for("index"))

    return render_template('register.html', title='Register', form=form)
Esempio n. 8
0
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = User(
            email=form.email.data,
            password=form.password.data,
            confirmed=False
        )
        db.session.add(user)
        db.session.commit()

        try:

            token = generate_confirmation_token(user.email)
            confirm_url = url_for('user.confirm_email', token=token, _external=True)
            html = render_template('user/activate.html', confirm_url=confirm_url)
            subject = "请激活您的账号"
            thread = Thread(target=send_email, args=[form.email.data, subject, html])
            thread.start()
            login_user(user)
        except Exception, e:
            # 邮箱地址错误
            traceback.print_exc()

        return redirect(url_for('user.unconfirmed'))
Esempio n. 9
0
def resend_confirmation():
    token = generate_confirmation_token(current_user.email)
    confirm_url = url_for('auth.confirm_email', token=token, _external=True)
    html = render_template('confirm_email.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('auth.unconfirmed'))
Esempio n. 10
0
def resend_confirmation():
    token = generate_confirmation_token(current_user.email)
    confirm_url = url_for('user.confirm_email', token=token, _external=True)
    html = render_template('user/activate.html', confirm_url=confirm_url)
    subject = "请确认您的邮件地址"
    send_email(current_user.email, subject, html)
    flash('一封新的帐号确认邮件已发往您的邮箱', 'success')
    return redirect(url_for('user.unconfirmed'))
Esempio n. 11
0
def resend_confirmation_email():
    # resending email
    token = generate_confirmation_token(current_user.email)
    confirm_url = url_for('users.confirm_email', token=token, _external=True)
    html = render_template('users/activate.html', confirm_url=confirm_url)
    subject = gettext(u'Please confirm your email')
    send_email(current_user.email, subject, html)

    flash(gettext(u'Confirmation email has been sent'), 'info')
    return redirect(url_for('users.account'))
Esempio n. 12
0
def send_confirmation_email(user):
    token = generate_confirmation_token(user.email)
    confirm_url = url_for('user_confirm', token=token, _external=True)
    app.logger.debug('Confirm url: {0}'.format(confirm_url))

    send_email(
        "Confirmación de cuenta para https://it-dojo.io", user.email,
        render_template("confirm_email.txt", user=user, token_url=confirm_url),
        render_template("confirm_email.html", user=user,
                        token_url=confirm_url))
Esempio n. 13
0
def test_reset_password_fail_validate(client):
    resp = client.get('/reset_password',
                      content_type="application/x-www-form-urlencoded",
                      data={'email': "*****@*****.**"})
    tok = generate_confirmation_token("*****@*****.**")
    client.post("/reset_password/new/{}".format(tok),
                content_type="application/x-www-form-urlencoded",
                data={
                    'password': "******",
                    'confirm': "abcdefg"
                })
Esempio n. 14
0
def resend_confirmation():
    try:
        token = generate_confirmation_token(current_user.email)
        confirm_url = url_for('user.confirm_email', token=token, _external=True)
        html = render_template('user/activate.html', confirm_url=confirm_url)
        subject = "请激活您的账号"
        thread = Thread(target=send_email, args=[current_user.email, subject, html])
        thread.start()
        flash(u'新的激活邮件已发送至您的邮箱,请查收!', 'success')
    except Exception, e:
        # 邮箱地址错误
        traceback.print_exc()
Esempio n. 15
0
def send_reset_passwd_email(user):
    token = generate_confirmation_token(user.email)
    reset_password_url = url_for('user_reset', token=token, _external=True)
    app.logger.debug('Reset password url: {0}'.format(reset_password_url))

    send_email(
        "Recuperación de cuenta para https://it-dojo.io", user.email,
        render_template("reset_password.txt",
                        user=user,
                        token_url=reset_password_url),
        render_template("reset_password.html",
                        user=user,
                        token_url=reset_password_url))
Esempio n. 16
0
def send_test_notification(test):
    token = generate_confirmation_token(str(test.id))
    access_url = url_for('test_confirm', token=token, _external=True)
    app.logger.debug('Interview url: {0}'.format(access_url))

    send_email(
        "Información de la prueba en https://it-dojo.io", test.email,
        render_template("test_notification.txt",
                        test=test,
                        access_url=access_url),
        render_template("test_notification.html",
                        test=test,
                        access_url=access_url))
Esempio n. 17
0
def resend_password():
    if request.method == 'POST':
        user = get_object_or_404(User, User.email == request.form['email'])
        token = generate_confirmation_token(user.email)
        reset_url = url_for('users.reset_password',
                            token=token,
                            _external=True)
        html = render_template('reset.html', reset_url=reset_url)
        subject = "Reset Password"
        send_email(user.email, subject, html)
        flash('A reset password email has been sent.', 'success')
        return redirect(url_for('users.login'))
    return render_template('resend.html')
Esempio n. 18
0
def resend_confirmation():
    if request.method == 'POST':
        user = get_object_or_404(User, User.email == request.form['email'])
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('users.confirm_email',
                              token=token,
                              _external=True)
        html = render_template('activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)
        flash('A new confirmation email has been sent.', 'success')
        return redirect(url_for('users.login'))
    return render_template('resend.html')
Esempio n. 19
0
def register():
    # models.delete_a_user('dfsdfsdfa')
    # models.delete_a_user('s1956124')
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data
        email_split = email.split("@")
        user = None
        if email_split[1].startswith('student'):
            user = User(form.username.data,
                        form.password.data,
                        email,
                        None,
                        None,
                        title=STUDENT,
                        confirmed=False,
                        confirmed_on=None)
            print("student")
        else:
            user = User(form.username.data,
                        form.password.data,
                        email,
                        None,
                        None,
                        title=HOUSEKEEPER,
                        confirmed=False,
                        confirmed_on=None)
            print("teacher")
        add_a_user_by_enity(user)
        # db.session.add(user)
        # db.session.commit()
        print("register")
        print(user.serialize())
        login_user(user)
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('auth.confirm_email',
                              token=token,
                              _external=True)
        html = render_template('confirm_email.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        # db.session.add(user)
        # db.session.commit()
        flash(
            'Congratulations, you are now a registered user! Please confirm your email first'
        )
        return redirect(url_for('auth.unconfirmed'))
    return render_template('signup.html', title='Register', form=form)
Esempio n. 20
0
def test_valid_register_with_confirm_email(tester_client):
    r = random.randint(1, 9999999)
    em = "{}@adfasdf.com".format(r)
    tester_client.post('/register',
                       content_type="application/x-www-form-urlencoded",
                       data={
                           'username': "******".format(r),
                           'email': em,
                           'password': "******",
                           'confirm': "asdfbasdf",
                           "accept_tos": "y"
                       })
    tok = generate_confirmation_token(em)
    tester_client.get("/confirm/{}".format(tok))
Esempio n. 21
0
def reset():
    form = EmailForm()
    if form.validate_on_submit():
        user = models.User.query\
            .filter_by(email=form.email.data).first_or_404()
        subject = "Password reset requested"
        token = generate_confirmation_token(user.email.lower())
        print(token)
        recover_url = url_for('reset_with_token', token=token, _external=True)
        html = render_template('recover.html', recover_url=recover_url)
        send_email(user.email, subject, html)
        flash('A reset link been sent via email.', 'success')
        return redirect(url_for('index'))
    return render_template('reset.html', form=form)
Esempio n. 22
0
def login():
    data = request.get_json(force=True)
    if not data or 'email' not in data or 'password' not in data:
        return jsonify(status='error', msg='参数错误')

    email = data.get('email')
    password = data.get('password')
    if email is None or password is None:
        return jsonify(status='error', msg='参数错误')
    user = User.query.filter_by(email=email).first()
    if not user or not user.verify_password(password):
        return jsonify(status='error', msg='用户不存在或密码错误')

    token = generate_confirmation_token(user.email)
    g.user = user
    return jsonify({'status': 'success', 'token': token.decode('ascii'), 'timeout': timeout})
Esempio n. 23
0
def send_reset_url():
    form = ResetForm(request.form)
    if form.validate_on_submit():
        try:

            token = generate_confirmation_token(form.email.data)
            reset_url = url_for('user.reset', token=token, _external=True)
            html = render_template('user/reset.html', reset_url=reset_url)
            subject = "密码重置"
            thread = Thread(target=send_email, args=[form.email.data, subject, html])
            thread.start()
        except Exception, e:
            # 邮箱地址错误
            traceback.print_exc()

        return jsonify(msg='success')
Esempio n. 24
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = models.User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        token = generate_confirmation_token(user.email.lower())
        confirm_url = url_for('confirm_email', token=token, _external=True)
        html = render_template('activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)
        flash('A confirmation email has been sent via email.', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 25
0
def forgot():
    form = ForgotPassword()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash('Recovery email has been sent to your inbox!', 'success')
            token = generate_confirmation_token(user.email)
            confirm_url = url_for('recovery_password',
                                  token=token,
                                  _external=True)
            html = render_template('emails/recover_password_email.html',
                                   confirm_url=confirm_url)
            subject = "Recover your password"
            send_email(user.email, subject, html)
        else:
            flash('No user found with this email. Try again.', 'danger')

    return render_template('forgot.html', title='Forgot password', form=form)
def enviat_admin():
    """confirma i envia el email per canviar password per administradors"""
    form = email_adminForm()
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('f_password_admin.html', form=form)
        else:
            correu = request.form['email']
            user = User.query.filter_by(email=correu).first()
            token = generate_confirmation_token(correu)
            confirm_url = url_for('confirm_email_admin', token=token, _external=True)
            html = render_template('canvi_pass.html', confirm_url=confirm_url)
            sender = ['*****@*****.**', user.email]
            msg = Message('Restablir Password', sender=sender[0], recipients=sender)
            msg.html = html
            mail.send(msg)
            return redirect(url_for('enviat_admin'))
    elif request.method == 'GET':
        return render_template('enviat.html', form=form)
Esempio n. 27
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(id=form.studentNumber.data,
                    email=form.email.data,
                    firstName=form.firstName.data,
                    LastName=form.lastName.data,
                    confirmed=False)
        user.set_password(form.password.data)
        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('email/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)
        flash('A confirmation email has been sent via email.', 'success')
        return redirect(url_for('unconfirmed'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 28
0
def reset_password():
    form = ResetForm(request.form)
    if form.validate():
        user = UserInfo.query.filter(UserInfo.email == form.email.data).first()
        token = generate_confirmation_token(user.email)

        user.password_token = token
        db.session.commit()

        change_url = url_for('change_password', token=token, _external=True)

        html = render_template('reset.html',
                               username=user.username,
                               change_url=change_url)
        subject = "Reset your password"
        send_email(user.email, subject, html)

        flash('A password reset email has been sent via email.', 'success')
        return redirect(url_for('login'))

    return render_template('reset_password.html', form=form)
Esempio n. 29
0
def forgot():
    form = ForgotForm(request.form)
    if form.validate_on_submit():

        user = User.query.filter_by(email=form.email.data).first()
        token = generate_confirmation_token(user.email)

        user.password_reset_token = token
        db.session.commit()

        reset_url = url_for('user.forgot_new', token=token, _external=True)
        html = render_template('user/reset.html',
                               username=user.email,
                               reset_url=reset_url)
        subject = "重置密码"
        send_email(user.email, subject, html)

        flash('一封密码重置邮件已发往您的邮箱', 'success')
        return redirect(url_for("main.home"))

    return render_template('user/forgot.html', form=form)
Esempio n. 30
0
def reset_password_request():

    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            token = generate_confirmation_token(user.email)
            confirm_url = url_for('auth.reset_password',
                                  token=token,
                                  _external=True)
            html = render_template('reset_password_email.html',
                                   confirm_url=confirm_url)
            subject = "Please confirm your email"
            send_email(user.email, subject, html)
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('auth.login'))
    return render_template('reset_password_request.html',
                           title='Reset Password',
                           form=form)
Esempio n. 31
0
def account():
    """Show users informations"""

    # get form
    form = AccountForm(request.form, obj=current_user)

    # verify the register form
    if form.validate_on_submit():
        new_email = str(form.email.data)

        if str(current_user.email) != new_email:
            # reset confirmation status
            current_user.confirmed = False
            current_user.confirmed_on = None

            # resending email
            token = generate_confirmation_token(new_email)
            confirm_url = url_for('users.confirm_email', token=token, _external=True)
            html = render_template('users/activate.html', confirm_url=confirm_url)
            subject = gettext(u'Confirm your account - Adventure')
            send_email(new_email, subject, html)
            flash(gettext(u'Confirmation email has been sent'), 'info')

        # if password has not changed we set it to previous
        if ((form.password.data is None) or (not form.password.data)):
            form.password.data = current_user.password
        else: # generate normal password
            form.password.data = generate_password_hash(form.password.data)

        # update user
        form.populate_obj(current_user)

        # update user in database
        db.session.commit()

        # everything is okay
        flash(gettext(u'The changes have been saved'), 'success')
        return redirect(url_for('users.account'))

    return render_template('users/account.html', form=form)
Esempio n. 32
0
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    password=form.password.data,
                    confirmed=False)
        db.session.add(user)
        db.session.commit()

        token = generate_confirmation_token(user.email)
        confirm_url = url_for('user.confirm_email',
                              token=token,
                              _external=True)
        html = render_template('user/activate.html', confirm_url=confirm_url)
        subject = "请确认您的帐号"
        send_email(user.email, subject, html)

        login_user(user)

        flash('一封帐号确认邮件已发送至您的邮箱', 'success')
        return redirect(url_for("user.unconfirmed"))

    return render_template('user/register.html', form=form)
Esempio n. 33
0
def email_register():
    form = EmailForm()
    if request.method == 'POST':
        form.email.data = form.email_name.data + current_app.config[
            'REGISTRATION_EMAIL_DOMAIN']
        if form.validate_on_submit():
            email = User.query.filter_by(email=form.email.data).first()
            if not email:
                token = generate_confirmation_token(form.email.data)
                flash(
                    '{}으로 이메일이 전송되었습니다. 전송된 URL을 통하여 회원가입을 진행해주십시오.'.format(
                        form.email.data), 'info')
                confirm_url = url_for('auth.confirm_email',
                                      token=token,
                                      _external=True)
                contents = render_template('/constant/email.html',
                                           confirm_url=confirm_url)
                send_email(form.email.data, '[CVIP] email verification',
                           contents)
                return redirect('/')
            else:
                flash('email already exist.', 'danger')
    return render_template('/main/auth/register.html', form=form)
Esempio n. 34
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(form.username.data, form.email.data, form.password.data,
                    False)
        # before adding into database, check if the email is already in the database.
        db.session.add(
            UserInfo(username=user.username,
                     email=user.email,
                     password=user.password,
                     register_date=datetime.datetime.now(),
                     confirmed=False,
                     confirmed_date=None))
        db.session.commit()

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

        flash('Registration Succeeded: ' + user.username)
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Esempio n. 35
0
def forgot_password():
    form = EmailForm()
    if form.validate_on_submit() and request.method == 'POST':
        email = form.email.data
        user = User.query.filter_by(email=email).first()
        if email:
            if user:
                token = generate_confirmation_token(email)
                confirm_url = url_for('routes.reset_password',
                                      token=token,
                                      _external=True)
                html = render_template('mail_reset_password.html',
                                       confirm_url=confirm_url)
                subject = "Please confirm your email"
                send_email(email, subject, html)

            else:
                time.sleep(2)
            return redirect(url_for('routes.reset_password_wait'))
        else:
            flash('Invalid Email')
            return render_template('forgot_password.html', form=form)
    else:
        return render_template('forgot_password.html', form=form)
Esempio n. 36
0
def test_new_confirm_email(client):
    tok2 = generate_confirmation_token("{}@blah.com".format(
        random.randint(1, 9999999)))
    client.get("/confirm/{}".format(tok2))
Esempio n. 37
0
def test_tokens(client):
    from app import token
    tok = token.generate_confirmation_token("*****@*****.**")
    token.confirm_token(tok)