Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 79 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
# Django-siteuser

集成用户注册,登录,上传头像,第三方登录等功能。此项目的目标是当建立新站点的时候,不再重头写用户系统。
Integrate user registration, login, upload avatar, third-party login and more. The goal of this project is to not write the user system when creating a new site.


## 注意
## attention

* 项目中的js依赖jQuery,所以请确保你的站点引入了jQuery
* 只实现了第三方帐号登录,并没有实现一个本地帐号绑定多个社交帐号的功能。
* siteuser并没有使用Django自带的User系统。
* js in the project depends on jQuery, so make sure your site introduces jQuery
* Only third-party account login is implemented, and the function of binding multiple social accounts to a local account is not implemented.
* siteuser does not use the User system that comes with Django.


## 功能
## Features

* 注册,登录
* 登录用户修改密码
* 忘记密码时重置密码
* 上传头像 (带有剪裁预览功能)
* 第三方帐号登录
* 消息通知
* register log in
* Login user to change password
* Reset password when you forget your password
* Upload avatar (with crop preview function)
* Third party account login
* notification


## 如何使用
## how to use

#### 安装
#### Installation

```bash
pip install django-siteuser
Pip install django-siteuser
```

同时会安装此项目的依赖:
At the same time, the dependencies of this project will be installed:

* [socialoauth](https://github.com/yueyoum/social-oauth) - 第三方登录
* [django-celery](https://github.com/celery/django-celery) - 异步发送邮件
* [socialoauth](https://github.com/yueyoum/social-oauth) - Third party login
* [django-celery](https://github.com/celery/django-celery) - Send mail asynchronously



#### 在你的模板中引入必要的js文件
#### Introducing the necessary js files in your template

```html
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/siteuser.js"></script>
```


#### 设置settings.py文件
#### Setting the settings.py file

* 首先设置 [django-celery](https://github.com/celery/django-celery)
* First set up [django-celery] (https://github.com/celery/django-celery)

* `siteuser` 加入到 `INSTALLED_APPS`
* Add `siteuser` to `INSTALLED_APPS`
```python
INSTALLED_APPS = (
# ...
Expand All @@ -58,95 +58,95 @@ pip install django-siteuser
)
```

`siteuser.users` **必须添加** 的app,另外两个一个用于上传头像,一个是简单的通知系统,**可以不添加**
`siteuser.users` is ** must add ** app, the other two are used to upload avatars, one is a simple notification system, ** can not be added **


* `siteuser.SITEUSER_TEMPLATE` 加入 `TEMPLATE_DIRS`
* Add `siteuser.SITEUSER_TEMPLATE` to `TEMPLATE_DIRS`

**注意**: 这里不是字符串,所以你需要在`settings.py` 文件中 先 `import siteuser`
**Note**: This is not a string, so you need to `import siteuser` in the `settings.py` file.


* `'siteuser.context_processors.social_sites'` 加入 `TEMPLATE_CONTEXT_PROCESSORS`
* `'siteuser.middleware.User'` 加入 `MIDDLEWARE_CLASSES`
* `url(r'', include('siteuser.urls'))` 加入到项目的 `urls.py`
* `AVATAR_DIR` - 告诉siteuser将上传的头像放置到哪个位置
* `USING_SOCIAL_LOGIN` 是否开启第三方帐号登录功能。**若不设置,默认为 False**
* `SOCIALOAUTH_SITES` - 仅在 `USING_SOCIAL_LOGIN`为True的情况下需要设置。第三方登录所需的配置。[见socialoauth文档](https://github.com/yueyoum/social-oauth/blob/master/doc.md#-settingspy)
* `SITEUSER_EXTEND_MODEL`
不设置此项,example一样可以运行,但实际项目中,肯定会根据项目本身来设定用户字段.
默认的字段请查看 [SiteUser](/siteuser/users/models.py#L108).
* Add `'siteuser.context_processors.social_sites'` to `TEMPLATE_CONTEXT_PROCESSORS`
* Add `'siteuser.middleware.User'` to `MIDDLEWARE_CLASSES`
* Add `url(r'', include('siteuser.urls'))` to the project's `urls.py`
* `AVATAR_DIR` - tells siteuser where to place the uploaded avatar
* `USING_SOCIAL_LOGIN` Whether to enable third-party account login. **If not set, the default is False**
* `SOCIALOAUTH_SITES` - Set only if `USING_SOCIAL_LOGIN` is True. The configuration required for third-party login. [See the socialauth documentation] (https://github.com/yueyoum/social-oauth/blob/master/doc.md#-settingspy)
* `SITEUSER_EXTEND_MODEL`
If you don't set this item, the example can run as well, but in the actual project, the user field will definitely be set according to the project itself.
For the default fields, please see [SiteUser](/siteuser/users/models.py#L108).

支持两种方式来扩展SiteUser字段
* 直接在`settings.py`中定义
Support two ways to extend the SiteUser field
* Defined directly in `settings.py`

```python
# project settings.py
from django.db import models
class SITEUSER_EXTEND_MODEL(models.Model):
From django.db import models
Class SITEUSER_EXTEND_MODEL(models.Model):
# some fields...
class Meta:
abstract = True
Class Meta:
Abstract = True
```

* 将此model的定义写在其他文件中,然后在settings.py中指定。
* Write the definition of this model in a different file and specify it in settings.py.


`example`使用的第二种,具体可以查看`example`项目.
The second type used by `example`, you can view the `example` project.

* `SITEUSER_ACCOUNT_MIXIN`
siteuser 提供了登录,注册的template,但只是登录,注册form的模板,
并且siteuser不知道如何将这个form模板嵌入到你的站点中,以及不知道在渲染模板的时候还要传入什么额外的context,
所以你需要在自己定义这个设置。
* `SITEUSER_ACCOUNT_MIXIN`
Siteuser provides login, registered template, but just login, registration form template,
And siteuser doesn't know how to embed this form template into your site, and doesn't know what additional context to pass in when rendering the template.
So you need to define this setting yourself.

`SITEUSER_EXTEND_MODEL` 一样,同样有两种方法定义,
* 直接在 `settings.py` 中定义
As with `SITEUSER_EXTEND_MODEL`, there are also two method definitions.
* Defined directly in `settings.py`

```python
class SITEUSER_ACCOUNT_MIXIN(object):
login_template = 'login.html' # 你项目的登录页面模板
register_template = 'register.html' # 你项目的注册页面模板
reset_passwd_template = 'reset_password.html' # 忘记密码的重置密码模板
change_passwd_template = 'change_password.html' # 登录用户修改密码的模板
reset_passwd_email_title = u'重置密码' # 重置密码发送电子邮件的标题
reset_passwd_link_expired_in = 24 # 重置密码链接多少小时后失效
Class SITEUSER_ACCOUNT_MIXIN(object):
Login_template = 'login.html' # Your project's login page template
Register_template = 'register.html' # Registration page template for your project
Reset_passwd_template = 'reset_password.html' # Forgot password reset password template
Change_passwd_template = 'change_password.html' # Login User Change Password Template
Reset_passwd_email_title = u'reset password' # reset password to send email header
Reset_passwd_link_expired_in = 24 # Reset password link expires after several hours

def get_login_context(self, request):
return {}
Def get_login_context(self, request):
Return {}

def get_register_context(self, request):
return {}
Def get_register_context(self, request):
Return {}
```

这两个方法正如其名,request是django传递给view的request,你在这里返回需要传递到模板中的context即可
在这里查看默认的 [SiteUserMixIn](/siteuser/users/views.py#L73)
These two methods are just like their names. The request is the request that django passes to the view. You can return the context that needs to be passed to the template.
Check the default [SiteUserMixIn] (/siteuser/users/views.py#L73) here.

* 第二中方法是将此Mixin定义在一个文件中,然后在settings.py中指定
* The second method is to define this Mixin in a file and then specify it in settings.py

`example`使用的第二种,具体可以查看`example`项目.
The second type used by `example`, you can view the `example` project.


* `SITEUSER_EMAIL`
* `SITEUSER_EMAIL`

siteuser自己写了发邮件的方法,所以也没使用Django自己的EMAI设置
所以你需要设置`SITEUSER_EMAIL`, [local_settings.py.example](/example/example/local_settings.py.example)
Siteuser wrote his own email method, so he didn't use Django's own EMAI settings.
So you need to set `SITEUSER_EMAIL`, see [local_settings.py.example](/example/example/local_settings.py.example)

其中需要说明的是 `display_from` 这个设置,
如果你没有自己架设SMTP SERVER,也没有购买发送邮件的服务,
而是直接在gmail, 163, sohu等email提供商那儿免费申请了个邮箱,
那么你的邮箱肯定是 name@gmail.com这种形式的。
这时候如果你想在别人的收件箱里显示 `abc@def.com`
那么就把 `display_from` 设置成此值。如果不设置,那么默认就是`from`
Which needs to be explained is the `display_from` setting.
If you don't set up SMTP SERVER yourself, you don't have to buy a service to send mail.
Instead, I applied for an email address directly at the email provider gmail, 163, sohu, etc.
Then your mailbox is definitely in the form of name@gmail.com.
At this time, if you want to display `abc@def.com` in someone else's inbox.
Then set `display_from` to this value. If not set, the default is `from`


#### 模板
#### Template

你需要自己完成 login.html, register.html, account_settings.html 模板。(名字可以自己取,只要在代码中
等对应起来就行),你只需要干一件事情,就是在你的模板的 `include` 相应的siteuser模板即可。
You need to complete the login.html, register.html, account_settings.html templates yourself. (The name can be taken by yourself, as long as it is in the code
Just wait for it.) You only need to do one thing, that is, the corresponding siteuser template in your template's `include`.

比如 login.html 中在你定义的位置 `{% include 'siteuser/login.html' %}`,
For example, login.html is in the location you defined `{% include 'siteuser/login.html' %}`,

account_settings.html 中 `{% include 'siteuser/upload_avatar.html' %}`
`{% include 'siteuser/upload_avatar.html' %} in account_settings.html

具体可以参考`example`项目
For details, please refer to the `example` project.

做完上面的设置后, `python manage.py validate` 检测无误后,syncdbrunserver 就可以测试注册,登录,头像,第三方登录
After the above settings, `python manage.py validate` is detected, syncdb, runserver can test registration, login, avatar, third-party login