Commit 835d597
committed
feat(core): 新用户注册时自动分配角色
新用户在注册时会被自动分配为普通用户角色,而第一个注册的用户会被分配为管理员角色。
- 在 `UserService` 的 `create_user` 方法中,添加了查询用户数量的逻辑。
- 根据用户数量,判断新用户的角色:如果用户数量为 0,则角色为 "admin";否则,角色为 "user"。
- 修改了 `users::ActiveModel` 中 `role` 字段的设置方式,使其根据上述逻辑动态设置用户角色。1 parent f8d67be commit 835d597
1 file changed
+5
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
87 | | - | |
| 91 | + | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
| |||
0 commit comments