サインアップフォームのカスタマイズ
このガイドでは、Signup items テーブルを使用してアプリケーションのサインアップフォームを作成する方法について説明します。
学習目標
- サインアップフォームのフィールドの追加、削除、並び替えを行います。
- フィールドを必須にし、正規表現で検証を行います。
- ルールを使用してフィールドの挙動を変更します。
- サインイン後にユーザーへ未入力フィールドの入力を求めます。
前提条件
- Enable signup がオンになっている アプリケーション
サインアップ項目について
Signup items の各行は、サインアップページの1つのフィールドまたは要素を表します。Casdoor SDKを通じて作成されたアプリケーションには、デフォルトで以下の項目が含まれます: ID, Username, Display name, Password, Confirm password, Email, Phone, Agreement。

列
| Column | 値 | 説明 |
|---|---|---|
| 名前 | — | Name of the signup item. |
| 表示 | True / False | Show or hide on the sign-up page. /api/signup ignores the values of hidden items. See Hidden items. |
| 必須 | True / False | Whether the field is mandatory. |
| プロンプト | True / False | Whether to ask for the field after sign-in if the account has no value for it. See Ask for missing fields after sign-in. |
| 正規表現 | — | Optional regex for client-side validation. |
| ラベル | — | For items starting with Text, use HTML for the field; otherwise replaces the item label. |
| カスタム CSS | — | CSS for this signup item. |
| ルール | Rule items | Rule that customizes this item (see table below). |
| アクション | — | Move up, move down, or delete. |
フォームの設定
- Casdoor管理コンソールで、アプリケーションの編集ページを開きます。
- Signup items で項目の追加、削除、並び替えを行い、各項目に対して Visible と Required を設定します。
- 対応している項目についてはルールを設定します。項目ルールを参照してください。
- アプリケーションを保存します。
例えば、検証が不要なメールフィールドを表示するには、Email項目を追加し、そのルールを No verification に設定します。

サインアップページは次のようになります:

項目ルール
| アイテム | ルール | 説明 |
|---|---|---|
| ID | Random / Incremental | User ID generation: random or incremental. |
| 表示名 | None / Real name / First, last | How to show the display name; First, last shows first and last name separately. |
| メール | Normal / No verification | Normal = require email verification; No verification = skip verification. |
| Phone | Normal / No verification | Normal = require phone verification; No verification = skip verification. |
| 同意 | None (shown as Only signup) / Signin / Signin (Default True) | The checkbox for the terms of use always starts checked, whatever the rule. If the item is required and the user unchecks it, submitting the form or clicking a provider button shows "Please accept the agreement!". To show the terms of use on the sign-in page, use the Agreement sign-in item. |
| 言語 | None / Label | Adds a language selector to the sign-up page. None = show the selector on its own; Label = show it with a text label. |
ユーザーにタグを選択させる
Tag 項目は、サインアップ時にユーザーが自分の タグ を選択できるリストを追加します。デフォルトでは非表示です。表示するには Visible をオンにします。
- 選択肢は項目の Options から取得されます。項目にオプションがない場合は、アプリケーションの Tags から取得されます。
- ユーザーが選択したタグは、アプリケーションの Default tag よりも優先されます。デフォルトタグは、ユーザーが何も選択しなかった場合にのみ適用されます。
正規表現による入力検証
- 項目の行で Regex にパターンを設定します。例えば、文字、数字、アンダースコアを含むユーザー名の場合、
^[a-zA-Z0-9_]+$などです。 - アプリケーションを保存します。
入力が一致しない場合、送信前にエラーが表示されます。検証は Username, Display name, First name, Last name, Affiliation、およびカスタムフィールドで機能します。
非表示項目
サインアップリクエストを検証する前に、POST /api/signup は、Signup items に存在しないか Visible がオフになっている項目に対応するすべてのフィールドをクリアします。APIを呼び出すクライアントは、アプリケーションのサインアップページに表示されないフィールドを設定できません。
| Item | Fields that Casdoor clears when the item is hidden |
|---|---|
| Username | username |
| Display name | name, firstName, lastName |
| First name | firstName |
| Last name | lastName |
| Password | password |
email, emailCode | |
| Phone | phone, countryCode, phoneCode |
| Email or Phone, Phone or Email | email, emailCode, phone, countryCode, phoneCode |
| Country/Region | region |
| ID card | idCard |
| Affiliation | affiliation |
| Bio | bio |
| Tag | tag |
| Education | education |
| Gender | gender |
| Languages | language |
複数の項目が所有するフィールド(例: firstName)は、これらの項目のうちいずれかが表示されている限り保持されます。
サインイン後に未入力フィールドの入力を求める
Prompted を使用すると、Casdoorはユーザーのアカウントに欠けているフィールド(例えば、電話番号を返さないプロバイダー経由でサインアップしたユーザーの電話番号など)について入力を求めます。
- Display name, Email, Phone, または Country/Region の行で、Visible と Prompted をオンにします。
- アプリケーションを保存します。
Affiliation において、Visible がオフの場合に Prompted スイッチが表示され、Prompted がオンの場合は所属情報の入力を求められます。Providers テーブルでは、プロバイダーの Prompted 列により、同様にそのプロバイダーへのリンクがユーザーに求められます。
ユーザーが OAuth 2.0 認可コードフロー(サードパーティプロバイダーによるサインインを含む)でアプリケーションにサインインする場合、Casdoor はクライアントへリダイレクトする前にアカウントを確認します。prompted フィールドが空の場合、ユーザーはまずプロンプトページ /prompt/<application> に移動します。すべてのフィールドに値が入力されている場合、ユーザーは直接リダイレクト URL に移動します。
プロンプトページでは:
- 新しいメールアドレスまたは電話番号、あるいは変更されたメールアドレスまたは電話番号には確認コードが必要です。Casdoor はコードの確認後にのみ保存します。電話番号には選択された国番号を使用し、デフォルトでは組織の最初の国番号になります。
- すべての prompted フィールドに値が入力され、かつ変更されたメールアドレスまたは電話番号それぞれに対してコードが入力されるまで、Submit and complete ボタンは無効のままです。
メールアドレスをユーザー名として使用
組織で Use Email as username がオンになっており、Username アイテムが非表示の場合、ユーザーのメールアドレスがユーザー名になります。Organizations を参照してください。