Esempio n. 1
0
def login_route():
    if current_user.is_authenticated:
        return redirect(url_for('.index'))
    else:
        print "LOGIN ROUTE: \t NOBODY AUTHENTICATED"
    form = EmailPasswordForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user == None:
            print ("LOGIN ROUTE \t NO RECOGNIZED EMAIL!\n")
            session.clear()
            error = "No recognized email!"
            errors={}
            errors['error'] = []
            errors['error'].append(error)
            return render_template('landing.html', form=form, errors=errors)
        if user.is_correct_password(form.password.data):
			login_user(user)
			print("LOGIN ROUTE \t USER LOGGED IN\n")
			return redirect(url_for('.index'))
        else:
            print("LOGIN ROUTE \t INCORRECT PASSWORD")
            session.clear()
            return redirect(url_for('.register_route'))
    else:
        print "LOGIN ROUTE \t FAILED LOGIN"
        print form.errors
        return render_template('landing.html', form=form, errors=form.errors)
    return render_template('landing.html', form=form)
Esempio n. 2
0
def submit_login():
    """
    attempt to log in
    @return: requested page or home page
    """
    if request.form['submit'] == "Login":
        login_form = EmailPasswordForm(request.form)
        if login_form.validate_on_submit():
            registered_user = User.get(login_form.login_email.data)
            if registered_user is None or registered_user.password is None:
                flash('Username is invalid', 'error')
                return render_template('login.html',
                                       loginform=login_form,
                                       forgotpw=ForgotPasswordForm())
            if not registered_user.check_password(login_form.password.data):
                flash('Password is invalid', 'error')
                return render_template('login.html',
                                       loginform=login_form,
                                       forgotpw=ForgotPasswordForm())
            login_user(registered_user)
            return redirect(request.args.get('next') or url_for('index'))
        else:
            return render_template('login.html',
                                   loginform=login_form,
                                   forgotpw=ForgotPasswordForm())
Esempio n. 3
0
def login():
    form = EmailPasswordForm()
    if form.validate_on_submit():

        # Check the password and log the user in
        # [...]

        return redirect(url_for('index'))
    return render_template('login.html', form=form)
Esempio n. 4
0
def signup():
    form = EmailPasswordForm()
    form2 = UsernamePasswordForm()

    if request.method == 'POST':

        if form.validate_on_submit():
            user = User(username=form.username.data,
                        email=form.username.data,
                        password=form.password.data)
            db.session.add(user)
            db.session.commit()

            uid = user.id
            defaultuser = User.query.filter_by(email='default').first_or_404()
            books = Book.query.filter_by(user_id=defaultuser.id).all()

            for b in books:
                bc = Book(b.title, b.synopsis, uid)
                db.session.add(bc)
                db.session.commit()

                for c in b.chapters:
                    cc = Chapter(c.title, c.synopsis, uid, bc.id)
                    db.session.add(cc)
                    db.session.commit()

                    for e in c.events:
                        ec = Event(uid, e.title, e.description, '-1', '-1',
                                   cc.id, e.event_occurs_percent)
                        db.session.add(ec)
                    db.session.commit()

            # SEND CONFIRMATION EMAIL
            subject = "Account created at {}.".format("Timelines")

            # Here we use the URLSafeTimedSerializer we created in `util` at the
            # beginning of the chapter
            token = ts.dumps(user.email, salt='recover-key')

            recover_url = url_for('reset_with_token',
                                  token=token,
                                  _external=True)

            html = render_template('email/create_account.html')

            # Let's assume that send_email was defined in myapp/util.py
            send_email(user.email, subject, html)
            flash('Email sent to: {}'.format(user.email))

            login_user(user, force=True)
            return redirect(url_for('index'))

    return render_template('signup.html', form=form, form2=form2)
Esempio n. 5
0
def login():
    form = EmailPasswordForm()
    error = ""
    if request.method == "POST":
        if form.validate_on_submit():
            if form.email.data == user.email and form.password.data == user.password:
                return "You are logged id"
            else:
                return "Wrong credentials!!"
        else:
            error = form.errors
    return render_template("login.html", form=form, error=error)
Esempio n. 6
0
def sendpw(request):
    """
    send a new password to the user. It return a mail with 
    a new pasword and a confirm link in. To activate the 
    new password, the user should click on confirm link.

    url : /sendpw/

    templates :  authopenid/sendpw_email.txt, authopenid/sendpw.html
    """

    msg = request.GET.get('msg','')
    if request.POST:
        form = EmailPasswordForm(request.POST)
        if form.is_valid():
            new_pw = User.objects.make_random_password()
            confirm_key = UserPasswordQueue.objects.get_new_confirm_key()
            try:
                uqueue = UserPasswordQueue.objects.get(
                        user=form.user_cache
                )
            except:
                uqueue = UserPasswordQueue(
                        user=form.user_cache
                )
            uqueue.new_password = new_pw
            uqueue.confirm_key = confirm_key
            uqueue.save()
            # send email 
            current_domain = Site.objects.get_current().domain
            subject = _("Request for a new password")
            message_template = loader.get_template(
                    'authopenid/sendpw_email.txt')
            message_context = Context({ 
                'site_url': 'http://%s' % current_domain,
                'confirm_key': confirm_key,
                'username': form.user_cache.username,
                'password': new_pw,
                'url_confirm': reverse('user_confirmchangepw'),
            })
            message = message_template.render(message_context)
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, 
                    [form.user_cache.email])
            msg = _("A new password has been sent to your email")
    else:
        form = EmailPasswordForm()
        
    return render('authopenid/sendpw.html', {
        'form': form,
        'msg': msg 
        }, context_instance=RequestContext(request))
Esempio n. 7
0
def signup():
    form = EmailPasswordForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user, force=True)
        #todo: create default event etc
        # create_defaults(user.id)
        return redirect(url_for('index'))

    return render_template('signup.html', form=form)
Esempio n. 8
0
def signin():
    form = EmailPasswordForm()
    form2 = UsernamePasswordForm()

    if request.method == 'POST':
        # pass
        try:
            if form2.validate_on_submit():
                user = User.query.filter_by(
                    username=form2.username.data).first_or_404()
                if user is None:
                    flash('Username or Password is invalid', 'error')
                    return redirect(url_for('login'))

                if user.is_correct_password(form2.password.data):
                    login_user(user, force=True)
                    flash('Logged in successfully')
                    return redirect(url_for('index'))
                else:
                    return redirect(url_for('signup'))

        except Exception as e:
            pass

    return render_template('signup.html', form=form, form2=form2)
Esempio n. 9
0
	def login():
		form = EmailPasswordForm()
		if form:
			if request.form['email'] == "*****@*****.**":
				return redirect(url_for('template'))
			else:
				redirect("https://google.com", code=302)
			
		return render_template('login.html', form=form)
Esempio n. 10
0
def create_account():
    form = EmailPasswordForm()
    if form.validate_on_submit():
        user = User(username=form.email.data,
                    password=form.password.data,
                    email=form.email.data)
        db.session.add(user)
        db.session.commit()
        uid = user.id

        defaultuser = User.query.filter_by(email='default').first_or_404()
        books = Book.query.filter_all(user_id=defaultuser.id).all()

        for b in books:
            bc = Book(b.title, b.synopsis, uid)
            db.session.add(bc)
            db.session.commit()

            for c in b.chapters:
                cc = Chapter(c.title, c.synopsis, uid, bc.id)
                db.session.add(cc)
                db.session.commit()

                for e in c.events:
                    ec = Event(uid, e.title, e.description, '-1', '-1', cc.id,
                               e.event_occurs_percent)
                    db.session.add(ec)
                db.session.commit()

        # Now we'll send the email confirmation link
        subject = "Confirm your email"

        token = ts.dumps(self.email, salt='email-confirm-key')

        confirm_url = url_for('confirm_email', token=token, _external=True)

        html = render_template('email/activate.html', confirm_url=confirm_url)

        # We'll assume that send_email has been defined in myapp/util.py
        send_email(user.email, subject, html)

        return redirect(url_for("index"))

    return render_template("accounts/create.html", form=form)
Esempio n. 11
0
def create_account():
    form = EmailPasswordForm()
    if form.validate_on_submit():
        user = User(username=form.email.data,
                    password=form.password.data,
                    email=form.email.data)
        db.session.add(user)
        db.session.commit()

        # Now we'll send the email confirmation link
        subject = "Confirm your email"

        token = ts.dumps(self.email, salt='email-confirm-key')

        confirm_url = url_for('confirm_email', token=token, _external=True)

        html = render_template('email/activate.html', confirm_url=confirm_url)

        # We'll assume that send_email has been defined in myapp/util.py
        send_email(user.email, subject, html)

        return redirect(url_for("index"))

    return render_template("accounts/create.html", form=form)
Esempio n. 12
0
def reset():
    """
    send reset password email to specified user email
    @return: refreshed page indicating success or failure
    """
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.get(form.forgot_email.data)
        subject = "Password reset requested"
        token = ts.dumps(user.id, salt='recover-key')
        recover_url = url_for('reset_with_token', token=token, _external=True)
        html = render_template('recover.html', recover_url=recover_url)
        msg = Message(subject,
                      sender=config.MAIL_USERNAME,
                      recipients=[user.id])
        msg.body = html
        mail.send(msg)
        flash('Password reset email sent to ' + user.id)
        return redirect(url_for('login'))
    return render_template('login.html',
                           loginform=EmailPasswordForm(),
                           forgotpw=ForgotPasswordForm())
Esempio n. 13
0
def login():
    """ load the login page """
    return render_template('login.html',
                           loginform=EmailPasswordForm(),
                           forgotpw=ForgotPasswordForm())