本文整理汇总了Python中forms.LoginForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.validate方法的具体用法?Python LoginForm.validate怎么用?Python LoginForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
"""
User login
"""
is_bookmarklet = request.args.get('b')
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
email = form.email.data
password = form.password.data
remember = form.remember.data
user_id = authenticate(email, password)
if user_id:
user_login(user_id)
resp = redirect(url_for('index'))
if remember:
g._persist_cookie_user = user_id
return resp
context = make_context({ 'form': form })
if is_bookmarklet:
tmpl = 'users/bookmarklet-login.html'
else:
tmpl = 'users/login.html'
return render_template(tmpl, **context)
示例2: signup
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def signup():
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
newUser(username=request.form.get('username'))
login_user(User(request.form.get('username')))
return redirect(url_for('home'))
return render_template('signup.html', form=form)
示例3: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
from uliweb.contrib.auth import authenticate, login
from forms import LoginForm
from uliweb.form import Submit, Tag
LoginForm.form_buttons = [Submit(value=_('Login'), _class="button")]
form = LoginForm()
if request.method == 'GET':
form.next.data = request.GET.get('next', '/')
return {'form':form, 'msg':''}
if request.method == 'POST':
flag = form.validate(request.params)
if flag:
f, d = authenticate(username=form.username.data, password=form.password.data)
if f:
request.session.remember = form.rememberme.data
login(form.username.data)
next = request.POST.get('next', '/')
return redirect(next)
else:
data = d
msg = form.errors.get('_', '') or _('Login failed!')
return {'form':form, 'msg':str(msg)}
示例4: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
"""
Log user in or display login form.
"""
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
#TODO: Hash password
hashed_pw = form.password.data
#hashed_pw = hash_password(form.password.data)
user = g.db_session.query(User).filter_by(email=form.email.data, password=hashed_pw).first()
if user is not None:
auth_user = AuthUser(user.id, user.username, user.role, user.confirmed)
if login_user(auth_user):
flash(u"Logged in!")
return redirect(request.args.get('next') or url_for('index'))
else:
flash(u"Sorry, but you could not be logged in.")
else:
flash(u"Invalid login credentials.")
try:
return render_template('login.html', form=form)
except TemplateNotFound:
abort(404)
示例5: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
form = LoginForm(request.form)
validates = request.method == 'POST' and form.validate()
if validates and User.check_password(request.form.get('username'), request.form.get('password')):
login_user(User(request.form.get('username')))
return redirect(request.args.get("next") or url_for("home"))
return render_template('login.html', form=form)
示例6: login_page
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login_page():
if g.user is not None and g.user.is_authenticated:
return redirect(url_for("invoices", invoice_type=CONST.INVOICE_TYPE[CONST.INVOICE_IN]))
form = LoginForm()
if request.method == "POST":
if not form.validate():
return render_template('login.html', form=form)
else:
login = form.login.data
password = form.password.data
user = User.query.filter_by(login=login.lower()).first()
if user is not None and user.check_password(password):
login_user(user)
# next = request.args.get('next')
# next_is_valid should check if the user has valid
# permission to access the `next` url
# if not next_is_valid(next):
# return flask.abort(400)
return redirect(url_for("first_page"))
else:
flash(u"Неверный логин или пароль.", "alert-danger")
return render_template('login.html', form=form)
示例7: admin_login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def admin_login():
form = LoginForm()
if request.method == 'POST' and form.validate():
user = User.query.filter_by(username=form.username.data).first()
login_user(user)
return redirect(url_for('admin_index'))
return render_template('admin_login.html', form=form)
示例8: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
form = LoginForm()
error = None
if request.method == 'POST':
if form.validate() == False:
return render_template('login.html', form=form)
else:
user = form.get_user()
# session['_id'] = str(user['id'])
if not user == None and form.password.data == user.password:
login_user(user)
print "user perfil"
print user.perfil
if user.perfil == '3':
user_json=json.loads(user.to_json())
identity = Identity(user_json)
print 'identity'
print user_json
identity_changed.send(current_app._get_current_object(),identity=identity)
# print(">> Identity: ",identity)
return render_template('about.html')
else:
flash(u"Credenciales incorrectas.")
return render_template('login.html', form=form)
elif request.method == 'GET':
# session.pop('username', None)
print ("FIN")
# return render_template('login.html', form=form)
return render_template('login.html', form=form)
return render_template('login.html', form=form)
示例9: index
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def index():
next = request.referrer
if next == None:
next = '/index'
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
ret = {'status':1,'message':''}
email = form.email.data
password = form.passwd.data
userInfo = User.query.filter(User.email == email).first()
if userInfo and userInfo.status == 1:
if getPasswd(password, userInfo.salt) == userInfo.password :
session['signin'] = True
session['user_id'] = userInfo.id
ret['status'] = 0
else:
ret['message'] = '您的账号和密码不匹配'
else:
ret['message'] = '您的账号不存在或者未激活!'
resp = make_response(json.dumps(ret))
if ret['status']== 0 and form.remember.data:
resp.set_cookie('user_id', value=str(userInfo.id),max_age=3600*24*7)
return resp
return render_template("web/users/login.html",form = form, next=next, user=g.user)
示例10: post
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def post(self):
form = LoginForm(self.request.POST)
if form.validate():
# Submit the query in the datastore
user_record = db.GqlQuery("SELECT * FROM User WHERE username='%s'"
% form.username.data)
user = user_record.get()
if user is not None:
if bcrypt.hashpw(form.passwd.data, user.password)\
== user.password:
self.session['username'] = form.username.data
self.redirect("/")
elif bcrypt.hashpw(form.passwd.data, user.password)\
!= user.password:
# self.redirect("/")
self.render("login.html", form=form,
error="Invalid Username Or Password",
username=self.session.get("username"))
elif user is None:
self.render("login.html", form=form,
error="Invalid Username Or Password",
username=self.session.get("username"))
else:
self.render("login.html", form=form,
error="Invalid Username Or Password",
username=self.session.get("username"))
示例11: LoginHandler
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
class LoginHandler(MainHandler):
def initialize(self, *args, **kwargs):
self.form = LoginForm(self.request.arguments)
def before_request(self):
super().before_request()
if self.current_user:
self.flash('您已经登录过了哦')
return self.redirect('/')
def get(self):
self.render("login.html", form=self.form)
@gen.coroutine
def post(self):
if self.form.validate():
user = yield User.asyncQuery(email=self.form.email.data).first()
if user:
verify = yield user.verify_password(self.form.password.data)
if verify:
if self.form.remember_me.data:
self.set_secure_cookie("user", user.email)
else:
self.set_secure_cookie("user", user.email,
expires_days=None)
self.flash('welcome back!')
return self.redirect(self.get_argument("next", "/"))
self.flash('Invalid email or passwd')
self.render("login.html", form=self.form)
示例12: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
if 'email' in session:
email = session['email']
user = User.query.filter_by(email=email).first()
firstname, lastname = user.firstname, user.lastname
return redirect(url_for('home', firstname=firstname, lastname = lastname))
form = LoginForm()
if request.method == "POST":
if form.validate() == False:
return render_template('login.html', form=form)
else:
email = form.email.data
password = form.password.data
user = User.query.filter_by(email=email).first()
if user is not None and user.check_password(password):
session['email'] = form.email.data
firstname = user.firstname
lastname = user.lastname
return redirect(url_for('home', firstname = firstname, lastname = lastname))
else:
return redirect(url_for('login'))
elif request.method == "GET":
return render_template('login.html', form=form)
示例13: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
form = LoginForm(next_url = request.args.get('next'))
error = None
if request.method == 'GET':
return render_template('login.html',form = form)
elif not form.validate():
error = get_error(form)
if error:
flash(error)
return render_template('login.html',form = form)
else:
user = User.query.filter_by(userid = form.userid.data).first()
if user is None:
error = CHECK_USERID_ERROR
elif user.password != form.password.data:
error = CHECK_PASSWORD_ERROR
else:
error = None
if error:
flash(error)
return render_template('login.html',form=form)
login_user(user)
return redirect(form.next_url.data or url_for('index'))
示例14: signin
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def signin():
'''
Creates a new User in the database. Checks if the user already exists and
logs the user in after adding it to the database.
Returns a redirect to the home page after login inc ase of POST or the sign
in html page in case of GET.
'''
# Create anti-forgery state token
state = ''.join(random.choice(
string.ascii_uppercase + string.digits) for x in xrange(32))
login_session['state'] = state
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
newUser = User(
username=form.username.data,
password=form.password.data)
users = User.query.all()
# check database is not empty
if users:
# check user doesn't exist
for user in users:
if newUser.username == user.username:
flash('User already exists, please try another user')
return redirect(url_for('signin'))
db.session.add(newUser)
db.session.commit()
users = User.query.all()
for user in users:
if user.username == newUser.username:
session['username'] = user.username
session['user_id'] = user.id
flash("User registered")
return redirect(url_for('home'))
else:
return render_template('signin.html', form=form, STATE=state)
示例15: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate [as 别名]
def login():
if account.user_is_logged_in():
return redirect(url_for("home"))
form = LoginForm(request.form)
if request.method == "POST" and form.validate():
try:
User.check_user_password(form.username.data,
form.password.data)
# password is good (no exceptions thrown)
account.user_log_in()
# When a "new user" first logs in, they go straight to the QA page.
# We do this for the purpose of our demo-- in a real app, the user
# would only go through this process the very first time they log in.
return redirect(url_for("question"))
except UsernameError:
#TODO: what is "the right way" to add new errors?
form.username.errors.append("Unrecognized username.")
except PasswordError:
form.password.errors.append("Incorrect password.")
return render_template("login.html", form=form)