本文整理汇总了Python中User.models.User.getUserByRawUsername方法的典型用法代码示例。如果您正苦于以下问题:Python User.getUserByRawUsername方法的具体用法?Python User.getUserByRawUsername怎么用?Python User.getUserByRawUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User.models.User
的用法示例。
在下文中一共展示了User.getUserByRawUsername方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: userLogin
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getUserByRawUsername [as 别名]
def userLogin(request):
username, password = '', ''
if request.META.has_key('HTTP_AUTHORIZATION'):
authmeth, auth = request.META['HTTP_AUTHORIZATION'].split(' ', 1)
if authmeth.lower() == 'basic':
auth = auth.strip().decode('base64')
username, password = auth.split(':', 1)
u = User.getUserByRawUsername(username)
if u!=None and u!=False and u.checkPasswd(password):
serializer = UserSerializer(u)
return JSONResponse(serializer.data)
return HttpResponse(status=404)
示例2: login
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import getUserByRawUsername [as 别名]
def login(request):
if request.method != 'POST':
return redirect('/')
try:
username = request.POST['username']
passwd = request.POST['passwd']
u = User.getUserByRawUsername(username)
if u!=None and u!=False and u.checkPasswd(passwd):
request.session['uid'] = u.uid
return redirect(referer(request))
else:
username = 'test#' + username
u = User.getUserByRawUsername(username)
if u!=None and u!=False and u.checkPasswd(passwd):
request.session['uid'] = u.uid
return redirect(referer(request))
else:
raise Exception('login err')
except Exception as e:
messages.error(request, u'用户名或密码错误')
return redirect(referer(request))