跳到主内容

概述

用户属性

As an authentication platform, Casdoor manages user accounts. 每个用户都有以下属性:

  • Owner:拥有用户的组织
  • Name:唯一的用户名
  • CreatedTime 创建时间
  • UpdatedTime
  • Id:每个用户的唯一标识符
  • Type
  • Password
  • PasswordSalt
  • PasswordOptions:密码复杂性选项
  • DisplayName:在用户界面中显示
  • FirstName
  • 姓氏
  • Avatar:链接到用户的头像
  • 永久头像
  • 电子邮件
  • 电话
  • 位置
  • 地址
  • 隶属
  • 标题
  • 身份证类型
  • 身份证
  • 主页
  • 生物
  • 标签
  • 区域
  • 语言
  • 性别
  • 生日
  • 教育
  • Balance: The user's account balance
  • 得分
  • 因果
  • 排名
  • IsDefaultAvatar
  • IsOnline
  • IsAdmin: Indicates whether the user is an administrator of their organization
  • IsGlobalAdmin: Indicates whether the user has permission to manage Casdoor
  • IsForbidden
  • IsDeleted: When a user is soft-deleted (IsDeleted = true), they cannot sign in through any authentication method, including OAuth providers. This prevents deleted users from re-registering via third-party login.
  • 注册应用程序
  • 哈希
  • 预哈希
  • 创建的IP
  • 最后登录时间
  • 最后登录IP
  • Roles: An array of the user's roles (extended field, read-only via User API)
  • Permissions: An array of the user's permissions (extended field, read-only via User API)

社交平台登录的唯一ID:

  • Github
  • Google
  • QQ
  • 微信
  • Facebook
  • 钉钉
  • 微博
  • Gitee
  • LinkedIn
  • Wecom
  • Lark
  • Gitlab
  • Adfs
  • Baidu
  • Casdoor
  • Infoflow
  • Apple
  • Azure AD
  • Azure AD B2C
  • Slack
  • Steam
  • Ldap

Organization Admin Privileges

Users with IsAdmin set to true have administrator privileges within their organization:

  • Full access to manage users, applications, and resources within their organization
  • Access to verification code records sent to users in their organization
  • Ability to configure organization-level settings and policies

Organization admins have elevated permissions but are scoped to their organization only. Global admins (built-in organization users) have full access across all organizations in the Casdoor instance.

User Tags

The Tag field allows you to categorize users for different purposes. Casdoor uses specific tag values for special user types:

  • normal-user: Standard users with full authentication capabilities
  • guest-user: Temporary users created through guest authentication without initial credentials
    • Automatically upgrade to normal-user when they set a proper username or password
    • Cannot sign in directly until they upgrade their account

You can also define custom tags to restrict application access. See Application Tags for more information.

Email Normalization

Casdoor normalizes all email addresses to lowercase to ensure uniqueness and prevent duplicate accounts. This means that user@example.com, User@Example.com, and USER@EXAMPLE.COM are treated as the same email address, complying with RFC 5321 standards.

This normalization happens automatically during:

  • User signup and account creation
  • User login and authentication
  • Email duplicate checking

Understanding Roles and Permissions Fields

The Roles and Permissions fields in the User object are extended fields that are dynamically populated when retrieving user data. These fields are not stored directly in the User table but are collected from the Roles and Permissions resources through the ExtendUserWithRolesAndPermissions() function.

Important: You cannot update roles and permissions through the /api/update-user endpoint, even when using the columns parameter. To manage user roles and permissions, you must use the dedicated APIs for Roles and Permissions resources.

To assign roles or permissions to users:

  • Roles: Use the Roles API endpoints to create and assign roles. Visit the Roles management page (e.g., https://door.casdoor.com/roles) or use the roles API.
  • Permissions: Use the Permissions API endpoints to create and assign permissions. Visit the Permissions management page (e.g., https://door.casdoor.com/permissions) or use the permissions API.

Using the Properties Field

The Properties field is a flexible key-value map (map[string]string) that allows you to store custom attributes for users beyond the predefined fields in the User schema. This is particularly useful when you need to:

  • Store organization-specific user attributes
  • Add custom metadata that doesn't fit into standard fields
  • Extend user profiles without modifying the core schema

从XLSX文件导入用户

您可以通过上传包含用户信息的XLSX文件来添加新用户或更新现有的Casdoor用户。

Getting Started

In the Admin Console, navigate to the Users page. You'll find two buttons for bulk user operations:

  • Download template: Generates an XLSX template with all available user fields and their localized column headers
  • Upload (.xlsx): Opens the upload dialog to import users from your XLSX file

导入用户

The template file includes headers in the format Display Name#field_name (e.g., Organization#owner), where the display name is localized to your language and the field name after # is used for import mapping. The comment prefix (everything before #) is automatically removed during import.

Upload Process

When you select an XLSX file, Casdoor displays a preview modal showing all the data to be imported. This allows you to review and verify the information before final submission. Once you confirm, click the upload button to import the users.

We also provide a sample XLSX file named user_test.xlsx in the xlsx folder with 5 test users for reference.

导入成功

Upload Permissions

User upload permissions depend on your admin role:

  • Global admins (users in the built-in organization with IsGlobalAdmin set to true) can upload users to any organization. The target organization is determined by the Owner field in the XLSX file.
  • Organization admins (users with IsAdmin set to true) can only upload users to their own organization. The system ensures that duplicate checking and user creation are scoped to the correct organization.

绕过密码加密

当从外部数据库迁移用户到Casdoor时,可能会出现您希望绕过或控制由organization默认密码类型方法提供的默认加密方法的情况。

这可以通过在用户导入过程中使用passwordType字段来实现。

备注

使用Bycrypt密码的用户

以下是API路由/api/add-user的POST体请求示例。

{
"owner": "组织",
"signupApplication": "first-app",
"email":"dev@dev.com",
"name": "dev",
"displayName": "开发者",
"password": "$2a$10$.o/iVyDE9Xk8ioywHDnQRu72RviOi6FPa1ujhusbSCZeg7VOa6MY6",
"passwordType":"bcrypt",
}

在这里,用户的密码已经使用bcrypt算法进行了加密,所以我们将passwordType指定为"bcrypt",以通知Casdoor不要再次加密它。