def login(): if 'username' in session: return redirect(request.referrer) form = LoginForm() if form.validate_on_submit(): name = form.username.data exists = Database.user_exists(name) if exists: details = Database.user_details_by_name(name) u = User(details[0], details[1], details[2]) # if user is already logged in get their name and if they have admin access, otherwise add it if 'username' in session: session['username'] = session.get('username') session['access'] = session.get('access') else: session['username'] = details[0] session['access'] = u.is_admin(details[2]) return redirect('/') else: flash("User not found!", 'noUser') return redirect('/login') return render_template('login.html', title="Login", form=form)
def iniciarSessao(request): data = {} if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): email=request.POST.get('email') password=request.POST.get('password') user = authenticate(email=email, password=password) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect("/userAccount/") else: data['failedLogin']=form.validation_errors['LOGIN_ERROR_2'] form = LoginForm(label_suffix='') else: data['failedLogin']=form.validation_errors['LOGIN_ERROR_1'] form = LoginForm(label_suffix='') else: form = LoginForm(label_suffix='') data['menu0Se1ect1'] = 'class=menuOpcSelected' data['form'] = form return render(request, 'login.tpl', data)
def login(): form = LoginForm() if form.validate_on_submit(): # login and validate the user... login_user(form.admin) flash("Logged in successfully.") return redirect(request.args.get("next") or url_for("index")) return render_template("login.html", form=form)
def post_login(): form = LoginForm() ref = request.values.get('next', None) if form.validate_on_submit(): # login and validate the user... user = User.objects.get(id=form.user.id) login_user(user) flash("Logged in successfully.") return redirect(ref or url_for("index")) return render_template("login.html", form=form, ref=ref)
def iniciarSessao(request): data = {} if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): email = request.POST.get('email') password = request.POST.get('password') user = authenticate(email=email, password=password) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect("/userAccount/") else: data['failedLogin'] = form.validation_errors[ 'LOGIN_ERROR_2'] form = LoginForm(label_suffix='') else: data['failedLogin'] = form.validation_errors['LOGIN_ERROR_1'] form = LoginForm(label_suffix='') else: form = LoginForm(label_suffix='') data['menu0Se1ect1'] = 'class=menuOpcSelected' data['form'] = form return render(request, 'login.tpl', data)
def login(): form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() user = db_sess.query(User).filter( User.email == form.email.data).first() if user and user.check_password(form.password.data): login_user(user, remember=form.remember_me.data) return redirect("/") return render_template('login.html', message="Incorrect login or password", form=form) return render_template('login.html', title='Authorization', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() user = db_sess.query(User).filter( User.email == form.email.data).first() if user and user.check_password(form.password.data): login_user(user, remember=form.remember_me.data) return redirect("/") return render_template('login.html', message="Неправильный логин или пароль", form=form) return render_template('login.html', title='Авторизация', form=form)
def login(): 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=form.remember_me.data) flash('You have been logged in!', 'success') return redirect(url_for('logged')) else: flash('Login Unsuccessful, Please check username and password', 'danger') return redirect(url_for('login')) return render_template('login.html', form=form)
def login(): if 'user' in session: print 'Found user in session: ', session['user'] return redirect(url_for('home_blueprint.home')) error = None if request.method == 'POST': username = request.form["username"] password = request.form["password"] user_type = request.form["type"] if user_type == "customer": sql = "SELECT user_id as id,firstname,lastname,gender,contact_number,username,email,password from customer where username=%s" else: sql = "SELECT owner_id as id,firstname,lastname,gender,contact_number,username,email,password from owner where username=%s" mycursor.execute(sql, [username]) result = mycursor.fetchone() #check if password matches if result: if bcrypt.check_password_hash(result['password'], password): del result['password'] session['user'] = result return redirect(url_for('home_blueprint.home')) else: error = "Username and password did not match." else: error = "Account does not exist." form = LoginForm() return render_template('loginform.html', title='Login', form=form, error=error)
def post(self, request): form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] response_data, user = authenticate_ldap(username, password, False) if user is not None and user.is_authenticated(): designations = user.designations.all() have_active_designation = any( [designation.is_active() for designation in designations]) if have_active_designation: login(request, user) next_ = request.GET.get('next') if next_ is not None: return redirect(next_) else: form.add_error( None, "You don't have content creation access. " "If you wish to get permissions, please contact Aman Gour" ) return render(request, self.template_name, {'form': form}) return redirect('content_home') else: form.add_error( None, "Unable to authenticate. Please check username/password") return render(request, self.template_name, {'form': form})
def login(): form = LoginForm() # if form.validate_on_submit(): # user = User.query.filter_by(email=form.email.data).first() # if user is not None and user.verify_password(form.password.data): # login_user(user, form.remember_me.data) # return redirect(request.args.get('next') or url_for('main.index')) # flash('Invalid username or password.') return render_template('auth/index.html', form=form)
def login(): form = LoginForm() if request.method == 'POST': if form.validate(): try: res = db.session.query(User).filter( User.user_email == form.user_email.data).one() except: form.user_email.errors = ['user doesnt exist'] return render_template('login.html', form=form) if res.user_password == form.user_password.data: newSession(res.user_email, res.user_password) return redirect('/') else: form.user_password.errors = ['wrong password'] return render_template('login.html', form=form) else: return render_template('login.html', form=form) else: return render_template('login.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): try: db_sess = db_session.create_session() user = db_sess.query(User).filter( User.email == form.login.data or User.username == form.login.data).first() if user and user.check_password(form.password.data): login_user(user, remember=form.remember_me.data) return redirect('/account/' + user.username) except Exception: return render_template('login.html', message="Такого пользователя не существует", form=form, bg_size=200) return render_template('login.html', title='Authorization', form=form, css_file=url_for('static', filename='css/style.css'))
def post(self, request): form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] response_data, user = authenticate_ldap(username, password, False) if user is not None and user.is_authenticated(): designations = user.designations.all() have_active_designation = any([designation.is_active() for designation in designations]) if have_active_designation: login(request, user) next_ = request.GET.get('next') if next_ is not None: return redirect(next_) else: form.add_error(None, "You don't have content creation access. " "If you wish to get permissions, please contact Aman Gour") return render(request, self.template_name, {'form': form}) return redirect('content_home') else: form.add_error(None, "Unable to authenticate. Please check username/password") return render(request, self.template_name, {'form': form})
def get(self, request): if request.user.is_authenticated(): return redirect('content_home') form = LoginForm() return render(request, self.template_name, {'form': form})
def login(): controller = LoginController(model=LoginForm(), login_user=login_user) return controller()
def login(): form = LoginForm() if form.validate_on_submit(): return 'success' return render_template('LoginTemplate.html', form=form, title='Login')