本文整理汇总了Python中forms.LoginForm类的典型用法代码示例。如果您正苦于以下问题:Python LoginForm类的具体用法?Python LoginForm怎么用?Python LoginForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LoginForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
def login(request):
"""
Logs a user in using Django's contrib.auth, and sets the cookie that
the cardstories client expects.
"""
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
# At this point, the user has already been authenticated by form
# validation (which simplifies user feedback on login errors).
auth_login(request, form.auth_user)
GravatarAvatar(form.auth_user).update()
# Redirect maintaining game_id, if set.
url = '%s%s' % (reverse(welcome), get_gameid_query(request))
return redirect(url);
else:
form = LoginForm()
context = {'registration_form': RegistrationForm(),
'login_form': form}
return render_to_response('cardstories/welcome.html', context,
context_instance=RequestContext(request,
processors=[common_variables]))
示例2: login
def login():
form = LoginForm()
if request.method == 'GET':
return render_template('login.html', title = 'Log in', form = form, providers = app.config['OPENID_PROVIDERS'])
if form.validate_on_submit():
return redirect('/')
return render_template('login.html', title = 'Log in', form = form)
示例3: post
def post(self):
form = LoginForm()
if form.validate_on_submit():
user = form._get_user()
login_user(user)
return redirect(url_for('admin.list'))
return render_template('login.html', form=form)
示例4: login
def login():
if current_user is not None and current_user.is_authenticated:
return redirect(url_for('home'))
form = LoginForm()
if request.method == "POST" and form.validate_on_submit():
# change this to actually validate the entire form submission
# and not just one field
username = form.username.data
password = form.password.data
user = UserProfile.query.filter_by(username=username,password=password).first()
# Get the username and password values from the form.
# using your model, query database for a user based on the username
# and password submitted
# store the result of that query to a `user` variable so it can be
# passed to the login_user() method.
# get user id, load into session
if user is not None:
login_user(user)
# remember to flash a message to the user
flash ('Logged in successfully.', 'success')
return redirect(url_for("securepage")) # they should be redirected to a secure-page route instead
else:
flash ('Username or Password incorrect','danger')
flash_errors(form)
return render_template("login.html", form=form)
示例5: account_login
def account_login(request):
form = LoginForm(request.POST or None)
redirect_to = request.REQUEST.get('next', '')
if request.method == "GET":
if redirect_to and request.user.is_authenticated():
return HttpResponseRedirect(redirect_to)
if request.method == 'POST':
if form.is_valid():
if not redirect_to:
redirect_to = settings.LOGIN_REDIRECT_URL
data = form.cleaned_data
user = authenticate(
username=data['username'],
password=data['password'])
if user:
login(request, user)
if data['remember_me']:
remember_user(request, user)
return HttpResponseRedirect(redirect_to)
else:
form.add_non_field_error(
_("Sorry, you have entered wrong E-mail or Password"))
return render_to_response('account_login.html',
RequestContext(request, {
'form': form,
'next': redirect_to,
}))
示例6: login
def login():
form = LoginForm()
if form.validate_on_submit():
login_user(form.user, remember=True)
flash("Logged In (%s)" % form.user.name, "success")
return redirect(request.args.get("next") or url_for("index"))
return render_template("login.html", login_form=form)
示例7: v1_login_json
def v1_login_json(request):
request.session.clear()
success = False
message = ""
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
authToken = getAuthToken(request, username, password)
if authToken != None:
# Prewarm the cache with location fixtures
cache.set('contacts-contact1:location', '{"name": "Unknown", "latitude": 35.668879, "longitude": 139.651436}', 3600)
cache.set('contacts-contact2:location', '{"name": "Unknown", "latitude": 35.667979, "longitude": 139.64999}', 3600)
cache.set('contacts-contact3:location', '{"name": "Unknown", "latitude": 35.668885, "longitude": 139.650634}', 3600)
cache.set('contacts-contact4:location', '{"name": "Unknown", "latitude": 35.668737, "longitude": 139.623203}', 3600)
request.session["authToken"] = authToken
request.session["username"] = username
request.session["password"] = password
success = True
message = "You're logged in."
else:
message = "Wrong username or password."
return {"success": success, "message": message}
示例8: login
def login():
'''
form is imported from froms.py
session["logged_in"] is a boolean wether or not someone is logged in
if you are already logged in you dont need to login, so you are redirected
to index
session['alias'] is the alias of the user that is currently logged in
session['allowTracking'] is wether or not the user is to be tracked
session['isMod'] is wether or not user is a moderator/advanced permission
flash returns a string to be delayed
'''
form = LoginForm()
if session.get('logged_in'):
return redirect(url_for('index'))
if form.validate_on_submit():
try:
user = User.objects(email=form.email.data)[0]
if check_password_hash(user.password, form.password.data):
session['logged_in'] = True
session['alias'] = user.alias
session['allowTracking'] = user.allowTracking
session['isMod'] = user.isMod
return redirect(url_for('index'))
else:
flash('Wrong password')
except:
flash('Wrong email, silly!')
return render_template('login.html', form = form)
示例9: login_view
def login_view(request):
mensaje = ""
#Si el usuario se ha autenticado
if request.user.is_authenticated():
return HttpResponseRedirect('/')
else:
#Si la solicitud fue enviada...
if request.method == "POST":
form = LoginForm(request.POST)
#Verificar si el formulario cumple con las condiciones de validacion
if form.is_valid():
#Limpia los datos ingresados de nombre de usuario y contrasena
username = form.cleaned_data['username']
password = form.cleaned_data['password']
#Procede a autenticar el usuario
usuario = authenticate(username=username,password=password)
#Verificar si el usuario existe y si esta activo
if usuario is not None and usuario.is_active:
#Enviar la peticion web con el usuario autenticado
login(request, usuario)
return HttpResponseRedirect('/')
#Si no se autentica el usuario
else:
#Mostrar un mensaje indicando los fallos
mensaje = "Usuario y/o password incorrecto"
form = LoginForm()
#Envio final del formulario con datos
ctx = {'form':form, 'mensaje':mensaje}
#Redirecciona a la pagina del login
return render_to_response('login.html', ctx, context_instance=RequestContext(request))
示例10: index
def index():
if g.user is None:
login_form = LoginForm(prefix="login")
registration_form = RegistrationForm(prefix="register")
button = request.form.get('button')
if button == 'login' and login_form.validate_on_submit():
user = login_form.user
user.touch()
session['username'] = user.username
return redirect(request.args.get('next', url_for('index')))
elif button == 'register' and registration_form.validate_on_submit():
count = User.query.count()
user = User(
registration_form.username.data,
generate_password_hash(registration_form.password.data),
registration_form.email.data,
False,
True,
bool(count == 0),
)
db.session.add(user)
db.session.flush()
email.send_account_created_email(user)
db.session.commit()
session['username'] = user.username
flash('Registration successful! Please check your e-mail so we can verify your address.')
return redirect(url_for('index'))
else:
return render_template('index.html',
login_form=login_form,
registration_form=registration_form)
else:
identity_tokens = list(g.user.identity_tokens.filter_by(enabled=True))
return render_template('index.html', identity_tokens=identity_tokens)
示例11: login
def login():
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('panel'))
form = LoginForm()
if form.validate_on_submit():
#logging_in_user = User.objects(username=form.username.data)
#logging_in_user = User.all().filter('username =', form.username.data).get()
logging_in_user = User.query(User.username == form.username.data).get()
if logging_in_user:
#logging_in_user = logging_in_user[0]
if pbkdf2_sha256.verify(form.password.data, logging_in_user.password):
#if True:
remember_me = False
if form.remember_me.data:
remember_me = True
login_user(logging_in_user, remember=remember_me)
return redirect(request.args.get('next') or url_for('panel'))
else:
flash('Invalid login. Please try again.', 'error')
redirect(url_for('login'))
else:
flash('Invalid login. Please try again.', 'error')
redirect(url_for('login'))
return render_template('users/login.html',
title='Sign In',
form=form)
示例12: user_login
def user_login(request):
if not request.user.is_anonymous():
return HttpResponseRedirect('/')
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
username = cd['username']
password = cd['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
if "next" in request.REQUEST:
return HttpResponseRedirect(request.REQUEST["next"])
else:
return HttpResponseRedirect("/")
else:
form.errors['password'] = u"帐号验证失败!"
context = RequestContext(request, {
'form': form })
return render_to_response("login.html", context)
else:
context = RequestContext(request, {
'form': form })
return render_to_response("login.html", context)
else:
form = LoginForm()
context = RequestContext(request, {
'form': form })
return render_to_response("login.html", context)
示例13: login
def login():
form = LoginForm()
if form.validate_on_submit():
return redirect('/auth')
return render_template('login.html',
title = 'Sign In',
form = form)
示例14: login
def login():
""" Creates new user if needed. Then logs the user in.
Note:
Stores phonenumber in a cookie
"""
form = LoginForm()
if request.method == "GET":
return render_template("login.html",form=form)
if form.validate_on_submit():
#convert phonenumber to an integer
phoneNumber = re.sub(r'[^0-9]','',str(form.number.data))
phoneNumer = int(phoneNumber)
hashPhone = hashVal(phoneNumber)
user = newUser(hashPhone)#none if user alreay exists
note = "Successfully Loggedin."
#user is trying to generate a password
if user == None:
user = getUser(hashPhone)
flash(note)
return redirect(url_for("getCode", phoneNumber = str(phoneNumber)))
#user is creating an account
note = "New Account created for " + str(phoneNumber) + ".\n" + note
flash(note)
return redirect(request.args.get("next") or url_for("login"))
示例15: home
def home():
"""
首页视图函数
1. 最近录入
2. 最近借阅
new_book_list: 最近录入新书列表(默认为6本, 依据时间[id]排序)
"""
form = LoginForm()
new_book_list = Book.query.order_by('-id').all()[:9]
get_book_list = Book.query.filter_by(status=True).order_by('start desc').all()[:2]
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user)
return redirect(url_for('user', id=current_user.id))
flash('用户名或密码错误!')
range_book_count = range(len(new_book_list)/6 + 1)
return render_template('home.html', new_book_list=new_book_list,
get_book_list=get_book_list, form=form,
range_book_count=range_book_count)