Mezzanine--加入註冊會員功能

Posted by: Max Chen | in Mezzanine | 1 year, 11 months ago |

Mezzanine--加入註冊會員功能

The accounts functionality is provided by the app mezzanine.accounts.

Adding it to your INSTALLED_APPS setting will enable signup, login, account updating, and password retrieval features for the public site.

Profiles

Profiles are implemented via the ACCOUNTS_PROFILE_MODEL setting. With mezzanine.accounts installed, you can create a profile model in one of your apps, with each of the profile fields defined, as well as a related field to Django’s user model. For example suppose we wanted to capture bios and dates of birth for each user:

```
In myapp/models.py

from django.db import models

class MyProfile(models.Model):
    user = models.OneToOneField("auth.User")
    date_of_birth = models.DateField(null=True)
    bio = models.TextField()
```


```
# In settings.py

INSTALLED_APPS = (
    "myapp",
    "mezzanine.accounts",
    # Many more
)

ACCOUNTS_PROFILE_MODEL = "myapp.MyProfile"
```

The bio and date of birth fields will be available in the signup and update profile forms, as well as in the user’s public profile page.

Profile pages are automatically made available when a profile model is configured

Restricting Account Fields

By default, Mezzanine will expose all relevant user and profile fields available in the signup and update profile forms, and the user’s profile page.

However you may want to store extra fields in user profiles, but not expose these fields to the user.

You may also want to have no profile model at all, and strip the signup and update profile forms down to only the minimum required fields on the user model, such as username and password.

Mezzanine defines the setting ACCOUNTS_PROFILE_FORM_EXCLUDE_FIELDS which allows you to define a sequence of field names, for both the user and profile models, that won’t be exposed to the user in any way.

Suppose we define a DateTimeField on the profile model called signup_date which we don’t want exposed.

We also might not bother asking the user for their first and last name, which are fields defined by Django’s user model.

In our settings.py module we would define:

```
ACCOUNTS_PROFILE_FORM_EXCLUDE_FIELDS = (
    "first_name",
    "last_name",
    "signup_date",
)
```

If you don’t want to expose the username field to the user, Mezzanine provides the setting ACCOUNTS_NO_USERNAME, which when set to True, will expose the email field as the sole login for the user.

Account Verification

By default, with mezzanine.accounts installed, any public visitor to the site can sign up for an account and will be logged in after signup.

However you may wish to validate that new accounts are only created by real people with real email addresses.

To enable this, Mezzanine provides the setting

ACCOUNTS_VERIFICATION_REQUIRED

which when set to True, will send new user an email with a verification link that they must click on, in order to activate their account.

Account Approval

You may also wish to manually activate newly created public accounts.

To enable this, Mezzanine provides the setting

ACCOUNTS_APPROVAL_REQUIRED

which when set to True, will set newly created accounts as inactive, requiring a staff member to activate each account in the admin interface.

A list of email addresses can be configured in the admin settings interface, which will then be notified by email each time a new account is created and requires activation.

Users are then sent a notification when their accounts are activated by a staff member.

參考來源: http://mezzanine.jupo.org/docs/user-accounts.html

tags: Mezzanine
Currently unrated
 or 

Subscribe

* indicates required

Recent Posts

Archive

2023
2022
2021

Categories

Apache 1

Data Science 2

Dbfit 1

Design Pattern 1

Devops 4

DigitalOcean 1

Django 1

English 3

Excel 5

FUN 4

Flask 3

Git 1

HackMD 1

Heroku 1

Html/Css 1

Linux 4

MDX 1

Machine Learning 2

Manufacture 1

Master Data Service 1

Mezzanine 18

Oracle 1

Postgresql 7

PowerBI 4

Powershell 4

Python 22

SEO 2

SQL Server 53

SQL Server Analytics Service 1

SQLite 1

Windows 1

database 8

work-experience 1

其他 1

投資入門 1

投資心得 2

時間管理 1

總體經濟 2

自我成長 3

資料工程 1

Tags

SEO(1) Github(2) Title Tag(2) ML(1) 李宏毅(1) SQL Server(18) Tempdb(1) SSMS(1) Windows(1) 自我成長(2) Excel(1) python Flask(1) python(5) Flask(2)

Authors

Max Chen (159)

Feeds

RSS / Atom

Mezzanine--加入註冊會員功能

© COPYRIGHT 2011-2022. Max的文藝復興. ALL RIGHT RESERVED.