示例#1
0
文件: views.py 项目: LordBH/Cupcake
def forgot_password():
    from models.models import User, ActivatedUsers
    context = {
        'msg': 'Please write your e-mail'
    }

    if request.method == 'POST':
        email = request.form.get('email').lower()
        q = User.query.filter_by(email=email).first()
        if User.clean_email(email) and q is not None:
            ActivatedUsers.send_email_for_password(email)
            context['msg'] = 'Check your email address and confirm the link'

            return render_template('reg/flash_message.html', context=context)

        context['msg'] = 'Wrong e-mail'

    return render_template('reg/email.html', context=context)
示例#2
0
文件: views.py 项目: LordBH/Cupcake
def register():
    from models.models import User, ActivatedUsers
    from run_app import db

    if request.method == 'GET':
        return render_template('reg/register.html', context={})

    context = {
        'last_name': request.form.get('last-name'),
        'first_name': request.form.get('first-name'),
        'email': request.form.get('email'),
        'msg': 'Validation error',
    }

    if request.method == 'POST':
        date = User.valid_date(context)
        if date:
            user = User(first_name=date.get('first_name'), last_name=date.get('last_name'),
                        email=date.get('email'), register=True)
            activate = ActivatedUsers(user)

            for x in [user, activate]:
                db.session.add(x)
            try:
                db.session.commit()
            except IntegrityError:
                context['msg'] = 'This email has already registered'
                return render_template('reg/register.html', context=context)

            activate.send_email()

            return render_template('reg/flash_message.html', context={'msg': 'Activate your e-mail'})
        else:

            return render_template('reg/register.html', context=context)

    context['msg'] = 'Problem with registration'

    return render_template('reg/register.html', context=context)