Gitlab: 取消邮箱验证的方法(API方式)

一时失言乱红尘 2023-02-28 01:44 115阅读 0赞

在这里插入图片描述

这篇文章介绍一下在Gitlab中通过API创建用户时取消邮箱验证的方法。

现象说明

使用API创建用户,登录时显示类似如下信息: You have to confirm your email address before continuing.

原因与对应方法

因为出现的原因是由于用户的邮箱验证,所以一般可以使用两种方式:

  • 完成当前用户有限验证:在gitlab的邮箱设定OK,而且用户邮箱也正确并能收到邮件,并且网络没有特殊访问设定限制的情况下:通过设定邮箱中的连接,点击打开完成验证,再次登录即可。
  • 创建用户时取消邮箱验证:在创建用户是指定是否要进行邮箱验证即可。

版本说明

本文memo的内容为Gitlab的Api为v4版本的情况,v3的对应方式略有不同

环境准备

docker-compose文件

  1. liumiaocn:gitlab liumiao$ cat docker-compose.yml
  2. version: '2'
  3. services:
  4. # Version Control service: Gitlab
  5. gitlab:
  6. image: gitlab/gitlab-ce:12.10.5-ce.0
  7. ports:
  8. - "32001:80"
  9. volumes:
  10. - ./log/:/var/log/gitlab
  11. - ./data/:/var/opt/gitlab
  12. - ./conf/:/etc/gitlab
  13. restart: "no"
  14. liumiaocn:gitlab liumiao$

事前准备

创建如下目录:

  1. liumiaocn:gitlab liumiao$ ls
  2. docker-compose.yml
  3. liumiaocn:gitlab liumiao$ mkdir -p log data conf
  4. liumiaocn:gitlab liumiao$ ls
  5. conf data docker-compose.yml log
  6. liumiaocn:gitlab liumiao$

启动

启动命令:docker-compose up -d

登录并创建apitoken

登录URL

  • http://localhost:32001

在这里插入图片描述
注:此处设定root用户密码,由于后续直接使用token进行用户创建,示例说明中不再直接需要使用root设定的密码。

创建api用的token

通过settings菜单或者直接使用如下URL,创建api用的token

  • http://localhost:32001/profile/personal\_access\_tokens

在这里插入图片描述

确认当前用户信息

执行命令
access_token=“7F2jdsYyeDsuhGnyTvPz”
gitlab_url=“localhost:32001”
curl -X GET -H “PRIVATE-TOKEN: a c c e s s t o k e n “ h t t p : / / {access_token}“ http:// accesst​oken”http://\{gitlab\_url\}/api/v4/users

执行日志示例:

  1. liumiaocn:gitlab liumiao$ access_token="7F2jdsYyeDsuhGnyTvPz"
  2. liumiaocn:gitlab liumiao$ gitlab_url="localhost:32001"
  3. liumiaocn:gitlab liumiao$ curl -X GET -H "PRIVATE-TOKEN: ${access_token}" http://${gitlab_url}/api/v4/users |jq .
  4. % Total % Received % Xferd Average Speed Time Time Time Current
  5. Dload Upload Total Spent Left Speed
  6. 100 808 100 808 0 0 7279 0 --:--:-- --:--:-- --:--:-- 7279
  7. [
  8. {
  9. "id": 1,
  10. "name": "Administrator",
  11. "username": "root",
  12. "state": "active",
  13. "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
  14. "web_url": "http://638d10b0f106/root",
  15. "created_at": "2020-07-19T02:20:24.191Z",
  16. "bio": null,
  17. "location": null,
  18. "public_email": "",
  19. "skype": "",
  20. "linkedin": "",
  21. "twitter": "",
  22. "website_url": "",
  23. "organization": null,
  24. "job_title": "",
  25. "work_information": null,
  26. "last_sign_in_at": "2020-07-19T02:24:26.401Z",
  27. "confirmed_at": "2020-07-19T02:20:23.698Z",
  28. "last_activity_on": "2020-07-19",
  29. "email": "admin@example.com",
  30. "theme_id": 1,
  31. "color_scheme_id": 1,
  32. "projects_limit": 100000,
  33. "current_sign_in_at": "2020-07-19T02:24:26.401Z",
  34. "identities": [],
  35. "can_create_group": true,
  36. "can_create_project": true,
  37. "two_factor_enabled": false,
  38. "external": false,
  39. "private_profile": false,
  40. "is_admin": true
  41. }
  42. ]
  43. liumiaocn:gitlab liumiao$

创建用户

使用如下示例命令创建用户

  1. curl -X POST -H "PRIVATE-TOKEN: ${access_token}" http://${gitlab_url}/api/v4/users \
  2. -H 'cache-control: no-cache' \
  3. -H 'content-type: application/json' \
  4. -d '{ "email": "test@outlook.com",
  5. "username": "liumiaocn",
  6. "password": "12341234",
  7. "name": "liumiao"
  8. }'

执行日志示例

  1. liumiaocn:gitlab liumiao$ curl -X POST -H "PRIVATE-TOKEN: ${access_token}" http://${gitlab_url}/api/v4/users \
  2. > -H 'cache-control: no-cache' \
  3. > -H 'content-type: application/json' \
  4. > -d '{ "email": "test@outlook.com",
  5. > "username": "liumiaocn",
  6. > "password": "12341234",
  7. > "name": "liumiao"
  8. > }' |jq .
  9. % Total % Received % Xferd Average Speed Time Time Time Current
  10. Dload Upload Total Spent Left Speed
  11. 100 841 100 736 100 105 1790 255 --:--:-- --:--:-- --:--:-- 2041
  12. {
  13. "id": 2,
  14. "name": "liumiao",
  15. "username": "liumiaocn",
  16. "state": "active",
  17. "avatar_url": "https://www.gravatar.com/avatar/e1128bc3a06f4735b039c9a60ba7c445?s=80&d=identicon",
  18. "web_url": "http://638d10b0f106/liumiaocn",
  19. "created_at": "2020-07-19T02:33:42.010Z",
  20. "bio": null,
  21. "location": null,
  22. "public_email": "",
  23. "skype": "",
  24. "linkedin": "",
  25. "twitter": "",
  26. "website_url": "",
  27. "organization": null,
  28. "job_title": "",
  29. "work_information": null,
  30. "last_sign_in_at": null,
  31. "confirmed_at": null,
  32. "last_activity_on": null,
  33. "email": "test@outlook.com",
  34. "theme_id": 1,
  35. "color_scheme_id": 1,
  36. "projects_limit": 100000,
  37. "current_sign_in_at": null,
  38. "identities": [],
  39. "can_create_group": true,
  40. "can_create_project": true,
  41. "two_factor_enabled": false,
  42. "external": false,
  43. "private_profile": false,
  44. "is_admin": false
  45. }
  46. liumiaocn:gitlab liumiao$

登录确认

在这里插入图片描述

取消邮箱验证方式API

v4的情况下,通过设定skip_confirmation即可对取消邮箱验证进行设定,示例命令如下所示:

  1. curl -X POST -H "PRIVATE-TOKEN: ${access_token}" http://${gitlab_url}/api/v4/users \
  2. -H 'cache-control: no-cache' \
  3. -H 'content-type: application/json' \
  4. -d '{ "email": "liumiaocn@outlook.com",
  5. "username": "liumiao",
  6. "password": "12341234",
  7. "name": "liumiao",
  8. "skip_confirmation": "true"
  9. }'

执行示例日志

  1. liumiaocn:gitlab liumiao$ curl -X POST -H "PRIVATE-TOKEN: ${access_token}" http://${gitlab_url}/api/v4/users \
  2. > -H 'cache-control: no-cache' \
  3. > -H 'content-type: application/json' \
  4. > -d '{ "email": "liumiaocn@outlook.com",
  5. > "username": "liumiao",
  6. > "password": "12341234",
  7. > "name": "liumiao",
  8. > "skip_confirmation": "true"
  9. > }'
  10. {"id":3,"name":"liumiao","username":"liumiao","state":"active","avatar_url":"https://www.gravatar.com/avatar/95c1f7ff72d71b448592a335ba80fb64?s=80\u0026d=identicon","web_url":"http://638d10b0f106/liumiao","created_at":"2020-07-19T02:40:24.899Z","bio":null,"location":null,"public_email":"","skype":"","linkedin":"","twitter":"","website_url":"","organization":null,"job_title":"","work_information":null,"last_sign_in_at":null,"confirmed_at":"2020-07-19T02:40:24.857Z","last_activity_on":null,"email":"liumiaocn@outlook.com","theme_id":1,"color_scheme_id":1,"projects_limit":100000,"current_sign_in_at":null,"identities":[],"can_create_group":true,"can_create_project":true,"two_factor_enabled":false,"external":false,"private_profile":false,"is_admin":false}liumiaocn:gitlab liumiao$

结果确认

输入用户名/密码进行登录
在这里插入图片描述
可以看到已经可以正常登录了
在这里插入图片描述

注意事项

注意api的版本为v3的时候,此设定选项为confirm。

发表评论

表情:
评论列表 (有 0 条评论,115人围观)

还没有评论,来说两句吧...

相关阅读