-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_admin.py
51 lines (33 loc) · 929 Bytes
/
create_admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# create admin with username and password
import re
import sys
import requests
import gitlab
URL = 'http://localhost'
SIGN_IN_URL = 'http://localhost/users/sign_in'
LOGIN_URL = 'http://localhost/users'
session = requests.Session()
sign_in_page = session.get(SIGN_IN_URL).content
count = 0
token = None
for l in sign_in_page.split('\n'):
m = re.search('name="authenticity_token" value="([^"]+)"', l)
if m:
count += 1
if count == 1:
break
if m:
token = m.group(1)
if not token:
print('Unable to find the authenticity token')
sys.exit(1)
data = {'new_user[name]': 'Yuqi',
'new_user[username]': 'root2',
'new_user[email]': '[email protected]',
'new_user[email_confirmation]': '[email protected]',
'new_user[password]': 'password',
'authenticity_token': token}
r = session.post(LOGIN_URL, data=data)
if r.status_code != 200:
print('Failed to register')
sys.exit(1)