Example #1
0
def register():
    form = LoginForm()
    if form.validate_on_submit():  # If all fileds pass the validations
        uname = form.uname.data
        password = form.password.data
        role = request.form.get('role')
        last_login = datetime.now()
        user = Login(uname=uname,
                     password=password,
                     role=role,
                     last_login=last_login)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        flash('Registration successfull ! Login to continue.',
              category='success')
        return redirect(url_for('login'))
    else:
        if current_user.is_authenticated:
            if current_user.role == 'customer':
                return redirect(url_for('customer_home'))
            else:
                return redirect(url_for('teller_home'))
        else:
            return render_template('register.html', page='register', form=form)
Example #2
0
def login_page():
    form = LoginForm()
    if form.validate_on_submit():
        attempted_user = User.query.filter_by(id=form.id.data).first()
        if attempted_user and attempted_user.check_password_correction(
                attempted_password=form.password.data):
            login_user(attempted_user)
            flash(f'Success! You are logged in as {attempted_user.username}',
                  category='success')
            return redirect(url_for('home_page'))
        else:
            flash('Email and password are not match! Please try again',
                  category='danger')

    return render_template('login.html', form=form)
Example #3
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Example #4
0
def login_view():
    try:
        form=LoginForm()
        if form.validate_on_submit():
            user=User.query.filter_by(username=form.username.data).first()
            if user and bcrypt.check_password_hash(user.password,form.password.data):
                login_user(user,remember=True)
                flash(f'You have successfully logged in {user.username}','success')
                return redirect(url_for('index'))
            else:
                flash('Please check your username or password','danger')
        return render_template('auth/login.html',title="Log in",form=form)
    except Exception as e:
        print(e)
        flash('Internal server error','danger')
        return redirect(url_for('index'))
Example #5
0
def login():
    login_form = LoginForm()

    if request.method == 'POST':
        if login_form.validate_on_submit():
            user = User.query.filter_by(email=login_form.email.data).first()
            if user and bcrypt.check_password_hash(user.password,
                                                   login_form.password.data):
                login_user(user)
                return redirect(url_for('murasaki'))

            else:
                flash(
                    'The email or password you entered was incorrect, please try again',
                    'warning')
                return redirect(url_for('login'))

    context = {
        'title': 'Log in to Murasaki Bank',
        'login_form': login_form,
    }
    return render_template('index.html', **context)
Example #6
0
def login(request):
    form=LoginForm()
    context={}
    context["form"]=form
    form=LoginForm(request.POST)
    if request.method=="POST":
        if form.is_valid():
            phone=form.cleaned_data.get("phonenumber")
            mpin=form.cleaned_data.get("mpin")

            try:

                object=account.objects.get(phonenumber=phone)
              
                if((object.phonenumber==phone) & (object.mpin==mpin)):
                    print("user exist")
                    return redirect("user")

            except Exception as e:
                print("invalid user")
                context["form"]=form
                return render(request,"login.html",context)

    return render(request, "login.html",context)