Điểm qua adonisjs/persona: 182 sao trên GitHub, viết chủ yếu bằng JavaScript. Opinionated user management service for AdonisJs
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
AdonisJs is all about removing redundant code from your code base. This add-on tries to do the same.
What is Persona?
Persona is a simple, functional service to let you create, verify and update user profiles.
Persona is not for everyone; if your login system is too complex and relies on many factors, Persona is not for you. However, persona works great for most use cases.
What does it do?
Helps you register new users.
Generates email verification tokens.
Validates credentials on login.
On email change, sets the user account to a pending state and re-generates the email verification token.
Allows changing passwords.
Allows recovering forgotten passwords.
What does it NOT do?
Does not generate any routes, controllers or views for you.
Does not send emails. However, it emits events that you can use to send emails.
Does not create sessions or generate JWT tokens.
Setup
Run the following command to grab the add-on from npm:
adonis install @adonisjs/persona
# for yarn
adonis install @adonisjs/persona --yarn
Follow up by registering the provider inside the providers array:
An array of database columns that will be used as uids. If your system allows username and emails both, then simply add them to this array.
email
email
The field to be used as email. Every time a user changes the value of this field, their account will be set to the pending state.
password
password
The field to be used as password.
model
App/Models/User
The user model to be used.
newAccountState
pending
The default account state for new users.
verifiedAccountState
active
The account state for users after verifying their email address.
dateFormat
YYYY-MM-DD HH:mm:ss
Your database date format, required for determining if the token has been expired or not.
validationMessages
function
A function that returns an object of messages to be used for validation. The syntax is the same as Validator custom messages.
Constraints
There are some intentional constraints in place.
Only works with Lucid models.
The App/Models/User must have a relationship setup with App/Models/Token and vice-versa.
class User extends Model {
tokens () {
return this.hasMany('App/Models/Token')
}
}
class Token extends Model {
user () {
return this.belongsTo('App/Models/User')
}
}
User table must have a string column called account_status.
API
Let's go through the API of persona.
register(payload, [callback])
The optional callback is invoked with the original payload just before the user is saved to the database. You can use it if you need to attach any other properties to the payload.
The register method takes the user input data and performs the following actions on it.
Validates that all uids are unique.
Checks that email is unique and is a valid email address.
Makes sure the password is confirmed.
Creates a new user account with the account_status = pending.
Generates and saves an email verification token inside the tokens table.
Emits a user::created event. You can listen for this event to send an email to the user.
Make sure to use querystring module to encode the token when sending via Email.
The optional callback is invoked with the user instance just before the password verification. You can use it to check for userRole or any other property you want.
Verifies the user credentials. The value of uid will be checked against all the uids.
You can define a function inside the config/persona.js file, which returns an object of messages to be used as validation messages. The syntax is the same as Validator custom messages.
The validationMessages method gets an action parameter. You can use it to customize the messages for different actions. Following is the list of actions.
register
login
emailUpdate
passwordUpdate
Events emitted
Below is the list of events emitted at different occasions.
Event
Payload
Description
user::created
{ user, token }
Emitted when a new user is created
email::changed
{ user, oldEmail, token }
Emitted when a user changes their email address
password::changed
{ user }
Emitted when a user changes their password by providing the old password
forgot::password
{ user, token }
Emitted when a user asks for a token to change their password
password::recovered
{ user }
Emitted when a user's password is changed using the token
Exceptions raised
The entire API is driven by exceptions, which means you will hardly have to write if/else statements.
This is great, since Adonis allows managing responses by catching exceptions globally.
ValidationException
Raised when validation fails. If you are already handling Validator exceptions, you won't have to do anything special.
InvalidTokenException
Raised when a supplied token, to verify an email or reset password with, is invalid.
Custom rules
At times, you may want to have custom set of rules when registering or login new users. You can override following methods for same.
The code can be added inside the hooks file or even in the registeration controller.
adonisjs/persona có 182 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/adonisjs/persona. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
adonisjs/persona có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho adonisjs/persona. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
adonisjs/persona còn đang phát triển không?
Commit gần nhất trên adonisjs/persona là 5.6 năm trước (theo timestamp GitHub). Repo có 23 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
adonisjs/persona là gì?
adonisjs/persona (adonisjs/persona) là dự án JavaScript trên GitHub. Theo mô tả gốc: Opinionated user management service for AdonisJs
Đọc thêm về adonisjs/persona ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/adonisjs/persona là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về persona?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về persona.