def login(request): if not request.POST: user = user_roles.get_userinfo(request) username = user and user.username or None data = {'username': username, 'post_path': request.get_full_path()} return render_to_response(request, 'admin/login.html', data) # login post back username = request.POST.get('username', None) password = request.POST.get('password', None) if not username or not password: error_message = "用户名或者密码不能都不填写,请重新登录。"; data = {'error_message': error_message, 'post_path': request.get_full_path()} return render_to_response(request, 'admin/login.html', data) r, session_id_or_msg = user_roles.login(username, password) if r == 0: redirect_to = request.GET.get("to", "/") response = HttpResponseRedirect(redirect_to) response.set_cookie(user_roles.SESSION_KEY, session_id_or_msg) return response else: data = {'username': username, 'post_path': request.get_full_path(), "error_message": session_id_or_msg} return render_to_response(request, 'admin/login.html', data)
def login(request): '''登陆''' if request.method == 'GET': response = render_to_response(request, "login.html") return response elif request.method == 'POST': username = request.POST.get('username',None) password = request.POST.get('password',None) if not username or not password: error_message = "用户名或者密码不能都不填写,请重新登录。" data = {'error_message': error_message, 'post_path': request.get_full_path()} return render_to_response(request, 'login.html', data) else: r, session_id_or_msg = user_roles.login(username, password) if r == 0: #redirect_to = request.GET.get(REDIRECT_FIELD_NAME, '/index/') response = redirect('/index/') response.set_cookie(user_roles.SESSION_KEY, session_id_or_msg) return response else: data = {'username': username, 'post_path': request.get_full_path(), "error_message": session_id_or_msg} return render_to_response(request, 'login.html', data)
def login(request): '''登陆''' if request.method == 'GET': response = render_to_response(request, "login.html") return response elif request.method == 'POST': username = request.POST.get('username', None) password = request.POST.get('password', None) if not username or not password: error_message = "用户名或者密码不能都不填写,请重新登录。" data = { 'error_message': error_message, 'post_path': request.get_full_path() } return render_to_response(request, 'login.html', data) else: r, session_id_or_msg = user_roles.login(username, password) if r == 0: #redirect_to = request.GET.get(REDIRECT_FIELD_NAME, '/index/') response = redirect('/index/') response.set_cookie(user_roles.SESSION_KEY, session_id_or_msg) return response else: data = { 'username': username, 'post_path': request.get_full_path(), "error_message": session_id_or_msg } return render_to_response(request, 'login.html', data)