参考にした記事
「SimpleAuthを参考にいじってみました(FuelPHP) : てるてる坊主」
この記事で解説されているとおりにして
PKGPATH/auth/classes/auth/login/easyauth.php (simpleauth.phpのコピー)を作成し、それを修正していきました。
以下に試したことを列挙。
ユーザー登録時のメールアドレスの入力を必須ではなく任意にする
データベースのほうでusersテーブルのemailフィールドがnullを許容するように変更してから、create_user()を以下のように変更しました。ついでに例外のメッセージを日本語化。public function create_user($username, $password, $email, $group = 1, Array $profile_fields = array()) { // メールアドレスが入力されたかどうか $is_posted_email = false; $password = trim($password); // メールアドレスが入力されていればフィルタリングする if (!empty($email)) { $is_posted_email = true; $email = filter_var(trim($email), FILTER_VALIDATE_EMAIL); } if (empty($username) or empty($password)) { throw new \SimpleUserUpdateException('ユーザーIDまたはパスワードが入力されていません', 1); } if ($is_posted_email && empty($email)) { throw new \SimpleUserUpdateException('メールアドレスが正しくありません', 1); } $same_users = \DB::select_array(\Config::get('easyauth.table_columns', array('*'))) ->where('username', '=', $username); if ($is_posted_email) { $same_users = $same_users->or_where('email', '=', $email); } $same_users = $same_users ->from(\Config::get('easyauth.table_name')) ->execute(\Config::get('easyauth.db_connection')); if ($same_users->count() > 0) { if ($is_posted_email && in_array(strtolower($email), array_map('strtolower', $same_users->current()))) { throw new \SimpleUserUpdateException('すでに登録されているメールアドレスです。', 2); } else { throw new \SimpleUserUpdateException('すでに使用されているユーザーIDです。', 3); } } $user = array( 'username' => (string) $username, 'password' => $this->hash_password((string) $password), 'email' => $email, 'group' => (int) $group, 'profile_fields' => serialize($profile_fields), 'last_login' => 0, 'login_hash' => '', 'created_at' => \Date::forge()->get_timestamp() ); $result = \DB::insert(\Config::get('easyauth.table_name')) ->set($user) ->execute(\Config::get('easyauth.db_connection')); return ($result[1] > 0) ? $result[0] : false; }
get_user_id()をuserのidだけを返すように変更
デフォルトではget_user_id()が返すのは[driverのid, userのid]という配列です。driverのIDを使うことはないと思い、userのidだけを返すように変更しました。public function get_user_id() { if (empty($this->user)) { return false; } return (int) $this->user['id']; }
こんな感じです。ニックネームや性別の入力を必須にしたりするのも簡単にできそうです。以上、備忘録でした。