暴力啟用 gitlab user
下這個標題不知道是不是很奇怪XD
最近在為自己的 team 開發一個 management 系統,於是決定在 gitlab 上開 project。用了 team 的 email 註冊,但是不知道為什麼總是收不到驗證信。於是…不小心找了個旁門左道 XD
Step 1
首先,要先登入 MySQL,找到 gitlab 所使用的資料庫,然後再找到 users
這個資料表。使用 describe users
查看該資料表的結構:
mysql> describe users;
+--------------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | UNI | | |
| encrypted_password | varchar(255) | NO | | | |
| reset_password_token | varchar(255) | YES | UNI | NULL | |
| reset_password_sent_at | datetime | YES | | NULL | |
| remember_created_at | datetime | YES | | NULL | |
| sign_in_count | int(11) | YES | | 0 | |
| current_sign_in_at | datetime | YES | | NULL | |
| last_sign_in_at | datetime | YES | | NULL | |
| current_sign_in_ip | varchar(255) | YES | | NULL | |
| last_sign_in_ip | varchar(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| name | varchar(255) | YES | MUL | NULL | |
| admin | tinyint(1) | NO | MUL | 0 | |
| projects_limit | int(11) | YES | | 10 | |
| skype | varchar(255) | NO | | | |
| linkedin | varchar(255) | NO | | | |
| twitter | varchar(255) | NO | | | |
| authentication_token | varchar(255) | YES | UNI | NULL | |
| theme_id | int(11) | NO | | 1 | |
| bio | varchar(255) | YES | | NULL | |
| failed_attempts | int(11) | YES | | 0 | |
| locked_at | datetime | YES | | NULL | |
| extern_uid | varchar(255) | YES | MUL | NULL | |
| provider | varchar(255) | YES | | NULL | |
| username | varchar(255) | YES | MUL | NULL | |
| can_create_group | tinyint(1) | NO | | 1 | |
| can_create_team | tinyint(1) | NO | | 1 | |
| state | varchar(255) | YES | | NULL | |
| color_scheme_id | int(11) | NO | | 1 | |
| notification_level | int(11) | NO | | 1 | |
| password_expires_at | datetime | YES | | NULL | |
| created_by_id | int(11) | YES | | NULL | |
| last_credential_check_at | datetime | YES | | NULL | |
| avatar | varchar(255) | YES | | NULL | |
| confirmation_token | varchar(255) | YES | UNI | NULL | |
| confirmed_at | datetime | YES | | NULL | |
| confirmation_sent_at | datetime | YES | | NULL | |
| unconfirmed_email | varchar(255) | YES | | NULL | |
| hide_no_ssh_key | tinyint(1) | YES | | 0 | |
| website_url | varchar(255) | NO | | | |
+--------------------------+--------------+------+-----+---------+----------------+
42 rows in set (0.01 sec)
查詢 users
table 裡的內容:
mysql> select id,email,confirmed_at,confirmation_token from users;
+----+---------------------------------+---------------------+----------------------+
| id | email | confirmed_at | confirmation_token |
+----+---------------------------------+---------------------+----------------------+
| 17 | abcd@abcd.defg.higk | 2014-07-07 03:39:04 | NULL |
| 18 | ab123@abcd.defg.higk | NULL | pynoSQoHEBjXYH5Ws7f8 |
+----+---------------------------------+---------------------+----------------------+
17 rows in set (0.00 sec)
可以發現,已驗證過的使用者,在 confirmed_at
這個欄位可以看到驗證的時間,而 confirmation_token
欄位則為 NULL;反之,未驗證過的 user 則是在 confirmation_token
裡有一個字串,而 confirmed_at
則為 NULL
Step 2
在 StackOverflow 上查到一篇: Incorrect url in confirmation mail
看到提問者打了一串 URL: http://localhost/users/confirmation?confirmation_token=pTy5sdjYjfymgcLy4gjp
於是我照著一樣格式的 URL,將 domain 與 token 替換掉,然後直接 enter。
神奇的事情來拉!!! 直接 login,並看到 Welcome to GitLab!
這時候在回去 MySQL 中查看:
mysql> select id,email,confirmed_at,confirmation_token from users;
+----+---------------------------------+---------------------+--------------------+
| id | email | confirmed_at | confirmation_token |
+----+---------------------------------+---------------------+--------------------+
| 18 | ab123@abcd.defg.higk | 2015-03-27 07:35:46 | NULL |
+----+---------------------------------+---------------------+--------------------+
17 rows in set (0.01 sec)
Ending~