楼主: jieforest

Django框架中的用户认证的实现

[复制链接]
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
61#
 楼主| 发表于 2012-12-24 23:42 | 只看该作者
password_reset_confirm(request[, uidb36, token, template_name, token_generator, set_password_form,post_reset_redirect])
Presents a form for entering a new password.

URL name: password_reset_confirm

Optional arguments:

uidb36: The user's id encoded in base 36. Defaults to None.

token: Token to check that the password is valid. Defaults to None.

template_name: The full name of a template to display the confirm password view. Default value is registration/password_reset_confirm.html.

token_generator: Instance of the class to check the password. This will default to default_token_generator, it's an instance of django.contrib.auth.tokens.PasswordResetTokenGenerator.

set_password_form: Form that will be used to set the password. Defaults to SetPasswordForm

post_reset_redirect: URL to redirect after the password reset done. Defaults to None.

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
62#
 楼主| 发表于 2012-12-24 23:43 | 只看该作者
Template context:

form: The form (see set_password_form above) for setting the new user's password.

validlink: Boolean, True if the link (combination of uidb36 and token) is valid or unused yet.

password_reset_complete(request[, template_name])

Presents a view which informs the user that the password has been successfully changed.

URL name: password_reset_complete

Optional arguments:

template_name: The full name of a template to display the view. Defaults to registration/password_reset_complete.html.

Helper functions

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
63#
 楼主| 发表于 2012-12-24 23:43 | 只看该作者
redirect_to_login(next[, login_url, redirect_field_name])

Redirects to the login page, and then back to another URL after a successful login.

Required arguments:

next: The URL to redirect to after a successful login.

Optional arguments:

login_url: The URL of the login page to redirect to. Defaults to settings.LOGIN_URL if not supplied.

redirect_field_name: The name of a GET field containing the URL to redirect to after log out. Overrides next if the given GETparameter is passed.

Built-in forms

If you don't want to use the built-in views, but want the convenience of not having to write forms for this functionality, the authentication system provides several built-in forms located in django.contrib.auth.forms:

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
64#
 楼主| 发表于 2012-12-24 23:43 | 只看该作者
class AdminPasswordChangeForm
A form used in the admin interface to change a user's password.

class AuthenticationForm
A form for logging a user in.

class PasswordChangeForm
A form for allowing a user to change their password.

class PasswordResetForm
A form for generating and emailing a one-time use link to reset a user's password.

class SetPasswordForm
A form that lets a user change his/her password without entering the old password.

class UserChangeForm
A form used in the admin interface to change a user's information and permissions.

class UserCreationForm
A form for creating a new user.

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
65#
 楼主| 发表于 2012-12-24 23:44 | 只看该作者
Limiting access to logged-in users that pass a test

To limit access based on certain permissions or some other test, you'd do essentially the same thing as described in the previous section.

The simple way is to run your test on request.user in the view directly. For example, this view checks to make sure the user is logged in and has the permission polls.can_vote:
  1. def my_view(request):
  2.     if not request.user.has_perm('polls.can_vote'):
  3.         return HttpResponse("You can't vote in this poll.")
  4.     # ...
复制代码

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表