def signup(): signup_form = loginForm() parameter = { 'signup_form': signup_form } #Validate the form if signup_form.validate_on_submit(): #Get the data username = signup_form.username.data password = signup_form.password.data user_doc = get_user(username) #If the user does not exists if user_doc.to_dict() is None: #Hash the password password_hash = generate_password_hash(password) user_data = UserData(username, password_hash) user_put(user_data) user = UserModel(user_data) login_user(user) flash('Welcome!') return redirect(url_for('index')) else: flash('The user already exists.') return render_template('signup.html', **parameter)
def login(): login_form = loginForm() context = { 'form': login_form } if login_form.validate_on_submit(): username = login_form.username.data password = login_form.password.data user_doc = get_user_by_id(username) if user_doc.to_dict() is not None: password_from_db = user_doc.to_dict()['password'] if check_password_hash(password_from_db, password): user_data = UserData(username, password) user = UserModel(user_data) login_user(user) flash('Bienvenido de nuevo', 'success') redirect(url_for('hello')) else: flash('Usuario y/o contrasena incorrectos', 'warning') return redirect(url_for('index')) return render_template('login.html', **context)
def hello(): user_ip = session.get('user_ip') login_form = loginForm() username = session.get('username') context = { 'login_form': login_form, 'username': username, } if login_form.validate_on_submit(): username = login_form.username.data password = login_form.password.data #session['username'] = username if username in useres: #password_db = user_document.to_dict().get('password') if password == password: for file in os.listdir(folder_path): os.remove(os.path.join(folder_path, file)) flash('Bienvenido de nuevo') return redirect(url_for('upload')) else: flash('ContraseƱa incorrecta !!') else: flash('Usuario incorrecto !!') return redirect(url_for('index')) return render_template('hello.html', **context)
def signup(): sign_form = loginForm() context = { 'form': sign_form } if sign_form.validate_on_submit(): username = sign_form.username.data password = sign_form.password.data user_doc = get_user_by_id(username) if user_doc.to_dict() is None: pass_hash = generate_password_hash(password) user_data = UserData(username, pass_hash) insert_user(user_data) user = UserModel(user_data) login_user(user) flash('Usuario creado correctamente', 'success') return redirect(url_for('hello')) else: flash('El usuario ya existe', 'warning') return render_template('signup.html', **context)
def Login(): form = loginForm() if form.validate_on_submit(): flash('Login requested for user {}, rememberMe={}'.format( form.username.data, form.rememberMe.data)) return redirect(url_for('index')) return render_template('login.html', title='Sign In', form=form)
def signup(): signup_form = loginForm() context = { 'signup_form': signup_form, } if signup_form.validate_on_submit(): username = signup_form.username.data password = signup_form.password.data print(signup_form.submit.data) user_document = get_user(username) if user_document.to_dict() is None: password_hash = generate_password_hash(password) #password_db = user_document.to_dict().get('password') user_data = UserData(username, password_hash) put_user(user_data) user_model = UserModel(user_data) login_user(user_model) flash('Bienvenido !!!') redirect((url_for('hello'))) else: flash('El usuario ya existe !') #session['username'] = username #flash('Registro exitoso') return redirect(url_for('index')) return render_template('signup.html', **context)
def login(request): """Renders the login page""" assert isinstance(request, HttpRequest) lf = loginForm() m = request.method if m == "GET": return render(request, 'app/login.html', { 'myForm': lf, 'title': 'Hello' }) else: # POST lf = loginForm(request.POST) if lf.is_valid(): # validate data uid = lf.cleaned_data.get('username') p = lf.cleaned_data.get('password') user = True #authenticate(username=uid, password=p) if user: request.session['username'] = uid request.session['user'] = user username = uid try: data = enrollment.objects.filter( username=username).values('classSec') except: data = '' classChoice = classSection.objects.all().values('classSec') print('Logged In') f = addClass() return render( request, 'app/index.html', { 'title': 'Home Page', 'year': datetime.now().year, 'data': data, 'classes': classChoice, 'myForm': f, }) else: return render(request, 'app/login.html', { 'myForm': lf, 'title': 'Hello' })
def sign_in(): 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_pass(form.password.data): login_user(user) return redirect(request.args.get('next') or url_for('main.index')) else: flash('Invalid credentials') return redirect(url_for('auth.sign_in')) return render_template('auth/login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = loginForm() if form.validate_on_submit(): user = Bard.query.filter_by(name=form.name.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) return redirect(url_for('index')) return render_template('login.html', title='Sign In', form=form)
def login(): login_form = loginForm() parameter = { 'login_form': loginForm() } #If the user is logged in, they won't have access to the login page if current_user.is_authenticated: return redirect(url_for('index')) #Add the username to the session, we use validate on submit, that function validates the form if login_form.validate_on_submit(): #Get username username = login_form.username.data password = login_form.password.data user_doc = get_user(username) if user_doc.to_dict() is not None: #Get the user password password_db = user_doc.to_dict()['password'] #If the password coincides with the ones in the DB if check_password_hash(password_db, password): user_data = UserData(username, password) user = UserModel(user_data) login_user(user) flash('Nice to see you!') redirect(url_for('hello')) else: flash('Wrong username/password') else: flash('The user does not exists') return redirect(url_for('index')) return render_template('login.html', **parameter)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) 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('index')) else: flash("Please Check your Email or password", "danger") return render_template('login.html', title='login', form=form)
def login(): if current_user.is_authenticated: if current_user.actype == "admin": return redirect(url_for('location')) return redirect(url_for('posts')) form = loginForm() if form.validate_on_submit(): user = User.query.filter_by(usn=form.usn.data.lower()).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=True) flash(f'logged in as {user.usn}', 'success') return redirect(url_for('posts')) else: flash('Check your USN and password and login again!', 'danger') return render_template("login.html", title="Login", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) login_form = loginForm() if login_form.validate_on_submit(): user = User.query.filter_by(username=login_form.username.data).first() if user is None or not user.verify_password(login_form.password.data): flash('invalid username or password') return redirect(url_for('login')) login_user(user, remember=login_form.is_remember.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=login_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(user_code=form.user_code.data).first() check = user.check_password(form.password.data) if user is None or not check: flash('Invalid username or password') return redirect(url_for('login')) # login_user(passenger, remember=form.remember_me.data) login_user(user) next_page = request.args.get('next') if not next_page: 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('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', 'danger') return redirect(url_for('login', next='/admin')) login_user(user, remember=False) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('admin') return redirect(next_page) return render_template('login.html', title='Login', form=form)
def login(): login_form = loginForm() context = { 'login_form': login_form, } if login_form.validate_on_submit(): username = login_form.username.data password = login_form.password.data user_document = get_user(username) if user_document.to_dict() is not None: password_db = user_document.to_dict().get('password') if password_db == password: user_data = UserData(username, password) user_model = UserModel(user_data) login_user(user_model) flash('Bienvenido de nuevo') redirect((url_for('hello'))) else: flash('La contraseƱa es incorrecta') else: flash('El usuario es incorrecto') #session['username'] = username #flash('Registro exitoso') return redirect(url_for('index')) return render_template('login.html', **context)