def login(): form = LoginForm() if form.validate_on_submit(): flash('Login requested for user {}, remember_me={}'.format( form.username.data, form.remember_me.data)) return redirect('/index') return render_template('login.html', title='Sign In', form=form)
def login(): if current_user.is_authenticated: if current_user.is_confirmed(): print("authenticated, confirmed") return redirect(url_for('index')) if not current_user.is_confirmed(): token = generate_confirmation_token(current_user.email) confirm_url = url_for('confirm_email', token=token, _external=True) email_sender.send(json.dumps({"email": current_user.email, "token":confirm_url})) flash('To complete your registration, confirm your email') print("authenticated, not confirmed") logout_user() return redirect(url_for('login')) form = LoginForm() if form.validate_on_submit(): user = USM.select(form.username.data, category='login') if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) if user.confirmed: print("authenticated, confirmed after login") next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) else: print("authenticated, not confirmed after login") token = generate_confirmation_token(user.email) confirm_url = url_for('confirm_email', token=token, _external=True) email_sender.send(json.dumps({"email": user.email, "token":confirm_url})) flash('Uups, you have not confirmed your email.') logout_user() return redirect(url_for('login')) return render_template('login.html', title='Sign In', form=form)
def index(): files_list = Files.query.order_by(Files.uploaded.desc()).all() login_form = LoginForm() time = datetime.now() return render_template('index.html', files_list=files_list, form=login_form, time=time)
def login(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): # cleaning the data email = form.cleaned_data['email'] password = form.cleaned_data['password'] login_data = {"email": email, "password": password} data_encoded = urllib.parse.urlencode(login_data).encode('utf-8') # our next page next = reverse('index') resp = urllib.request.Request( 'http://exp:8000/exp/users/login/', data=data_encoded, method='POST') #resp_json = json.dumps(resp) req = urllib.request.urlopen(resp).read().decode('utf-8') resp_json = json.loads(req) if not resp or not resp_json['ok']: # todo figure out how to display possible errors here return render(request, 'web_app/login.html', {'form': form, 'message': "Invalid login. Please try again"}) # at this point we can log them in authenticator = resp_json['authenticator'] response = HttpResponseRedirect(reverse('index')) if 'next' in request.POST: response = HttpResponseRedirect( reverse(request.POST.get('next'))) response.set_cookie("user_id", resp_json['user_id']) response.set_cookie("auth", authenticator) return response else: return render(request, 'web_app/login.html', {'form': form}) else: if request.COOKIES.get('auth'): base_url = reverse('index') query_string = urllib.parse.urlencode( {'already_logged_in': True}) url = '{}?{}'.format(base_url, query_string) return HttpResponseRedirect(url) form = LoginForm() context = {'form': form} if request.GET.get('redirect_create'): context['redirect_create'] = True return render(request, 'web_app/login.html', context)
def process_login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter(User.username == form.username.data).first() if user and user.check_password(form.password.data): login_user(user) flash('Вы вошли на сайт') return redirect(url_for('start.start')) flash('Неправильное имя пользователя или пароль') return redirect(url_for('user.login'))
def login(): if current_user.is_authenticated: return redirect(url_for('start.index')) title = 'Авторизация' login_form = LoginForm() time = datetime.now() return render_template('login.html', page_title=title, form=login_form, time=time)
def Login(): form = LoginForm() if form.validate_on_submit(): ## lets create a temporary check till we have a datbase created if form.email.data == '*****@*****.**' and form.password.data == 'Adarsh@123': flash('Login Succesfull !', 'success') return redirect(url_for('home')) else: flash( 'Login Unsuccessful. Either Invalid login credentials or Create an account', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template('login.html', title='Sign In', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('Home')) form = LoginForm() if form.validate_on_submit(): # if form.email.data == '*****@*****.**' and form.password.data =='password': 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') # flash('You have been logged in!', 'success') return redirect(next_page) if next_page else redirect( url_for('Home')) else: flash('Login Failed', 'danger') return render_template('login.html', titile='Log In', form=form)
def login(): logger = logging.getLogger(__name__) if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): user = User(username=os.environ.get('web_username'), password=os.environ.get('web_password')) user_test = User(username=form.username.data, password=form.password.data) if user_test.username != user.username or user_test.password != user.password: flash('Invalid username or password') logger.info( "Invalid username or password. User %s attempted login", form.username.data) return redirect(url_for('login')) logger.info("User %s logged in", form.username.data) login_user(user_test, remember=form.remember_me.data) return redirect(url_for('index')) return render_template('login.html', title='Sign In', form=form)
def login(): print('Login') form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None: flash('User does not exist') return redirect(url_for('login')) if not user.check_password(form.password.data): flash('Password is incorrect') return redirect(url_for('login')) if not user.is_active: flash('Confirm your email') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template('login.html', title='Sign In', form=form)