ユーザー作成(管理者向け)
現時点では管理画面からのユーザー登録機能は未実装です。システム管理者は以下の方法でユーザーを作成できます。
方法 1: psql で直接作成
1. パスワードハッシュの生成
bcrypt でパスワードをハッシュ化する必要があります。
bash
# Node.js を使用
node -e "const bcrypt = require('bcryptjs'); console.log(bcrypt.hashSync('your_password', 10))"
# または htpasswd を使用
htpasswd -bnBC 10 "" your_password | tr -d ':\n'2. ユーザーの挿入
sql
-- Docker環境の場合
docker exec -it iwa-cms-postgres-1 psql -U postgres -d iwa_cms
-- ユーザー作成
INSERT INTO users (name, email, password)
VALUES (
'ユーザー名',
'user@example.com',
'$2a$10$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -- bcryptハッシュ
);確認用クエリ
sql
-- ユーザー一覧
SELECT id, name, email, created_at FROM users;方法 2: gRPC で作成
Postman での手順
gRPC リクエストの作成
- Postman で「New」→「gRPC」を選択
- URL:
localhost:8080(cms-service)
proto ファイルのインポート
- 「Service definition」タブで「Import .proto file」
pkg/proto/cms/v1/user.protoをインポート- 依存ファイルも必要に応じてインポート
メソッドの選択
cms.v1.UserService/CreateUserを選択
リクエストボディ
json{ "name": "ユーザー名", "email": "user@example.com", "password": "your_password" }送信
- 「Invoke」ボタンをクリック
grpcurl での手順
bash
# grpcurl のインストール(macOS)
brew install grpcurl
# ユーザー作成
grpcurl -plaintext \
-d '{
"name": "ユーザー名",
"email": "user@example.com",
"password": "your_password"
}' \
localhost:8080 \
cms.v1.UserService/CreateUser注意
gRPC エンドポイントは現在認証なしでアクセス可能です。
テーブル構造
users テーブル
| カラム | 型 | 説明 |
|---|---|---|
id | UUID | 自動生成 |
name | TEXT | ユーザー名 |
email | CITEXT | メールアドレス(大文字小文字区別なし、ユニーク) |
password | TEXT | bcrypt ハッシュ |
created_at | TIMESTAMPTZ | 作成日時 |
updated_at | TIMESTAMPTZ | 更新日時 |