メインコンテンツにスキップ

サインアップフォームのカスタマイズ

このガイドでは、Signup items テーブルを使用してアプリケーションのサインアップフォームを作成する方法について説明します。


学習目標​

  • サインアップフォームのフィールドの追加、削除、並び替えを行います。
  • フィールドを必須にし、正規表現で検証を行います。
  • ルールを使用してフィールドの挙動を変更します。
  • サインイン後にユーザーへ未入力フィールドの入力を求めます。

前提条件​


サインアップ項目について​

Signup items の各行は、サインアップページの1つのフィールドまたは要素を表します。Casdoor SDKを通じて作成されたアプリケーションには、デフォルトで以下の項目が含まれます: ID, Username, Display name, Password, Confirm password, Email, Phone, Agreement。

Signup items table of an application

列​

Column値説明
名前—Name of the signup item.
表示True / FalseShow or hide on the sign-up page. /api/signup ignores the values of hidden items. See Hidden items.
必須True / FalseWhether the field is mandatory.
プロンプトTrue / FalseWhether 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 itemsRule that customizes this item (see table below).
アクション—Move up, move down, or delete.

フォームの設定​

  1. Casdoor管理コンソールで、アプリケーションの編集ページを開きます。
  2. Signup items で項目の追加、削除、並び替えを行い、各項目に対して Visible と Required を設定します。
  3. 対応している項目についてはルールを設定します。項目ルールを参照してください。
  4. アプリケーションを保存します。

例えば、検証が不要なメールフィールドを表示するには、Email項目を追加し、そのルールを No verification に設定します。

Signup items configured with an email field without verification

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

Sign-up page with an email field

項目ルール​

アイテムルール説明
IDRandom / IncrementalUser ID generation: random or incremental.
表示名None / Real name / First, lastHow to show the display name; First, last shows first and last name separately.
メールNormal / No verificationNormal = require email verification; No verification = skip verification.
PhoneNormal / No verificationNormal = 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 / LabelAdds 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 よりも優先されます。デフォルトタグは、ユーザーが何も選択しなかった場合にのみ適用されます。

正規表現による入力検証​

  1. 項目の行で Regex にパターンを設定します。例えば、文字、数字、アンダースコアを含むユーザー名の場合、^[a-zA-Z0-9_]+$ などです。
  2. アプリケーションを保存します。

入力が一致しない場合、送信前にエラーが表示されます。検証は Username, Display name, First name, Last name, Affiliation、およびカスタムフィールドで機能します。

非表示項目​

サインアップリクエストを検証する前に、POST /api/signup は、Signup items に存在しないか Visible がオフになっている項目に対応するすべてのフィールドをクリアします。APIを呼び出すクライアントは、アプリケーションのサインアップページに表示されないフィールドを設定できません。

ItemFields that Casdoor clears when the item is hidden
Usernameusername
Display namename, firstName, lastName
First namefirstName
Last namelastName
Passwordpassword
Emailemail, emailCode
Phonephone, countryCode, phoneCode
Email or Phone, Phone or Emailemail, emailCode, phone, countryCode, phoneCode
Country/Regionregion
ID cardidCard
Affiliationaffiliation
Biobio
Tagtag
Educationeducation
Gendergender
Languageslanguage

複数の項目が所有するフィールド(例: firstName)は、これらの項目のうちいずれかが表示されている限り保持されます。

サインイン後に未入力フィールドの入力を求める​

Prompted を使用すると、Casdoorはユーザーのアカウントに欠けているフィールド(例えば、電話番号を返さないプロバイダー経由でサインアップしたユーザーの電話番号など)について入力を求めます。

  1. Display name, Email, Phone, または Country/Region の行で、Visible と Prompted をオンにします。
  2. アプリケーションを保存します。

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 を参照してください。

関連項目​