Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
1cc1c288
Commit
1cc1c288
authored
8 years ago
by
Megan Henning
Browse files
Options
Downloads
Patches
Plain Diff
Add reset-registration endpoint
parent
59a018d3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/api.py
+5
-4
5 additions, 4 deletions
api/api.py
api/auth/__init__.py
+12
-0
12 additions, 0 deletions
api/auth/__init__.py
api/handlers/userhandler.py
+16
-1
16 additions, 1 deletion
api/handlers/userhandler.py
api/web/base.py
+2
-0
2 additions, 0 deletions
api/web/base.py
with
35 additions
and
5 deletions
api/api.py
+
5
−
4
View file @
1cc1c288
...
...
@@ -116,10 +116,11 @@ endpoints = [
route
(
'
/self/avatar
'
,
UserHandler
,
h
=
'
self_avatar
'
,
m
=
[
'
GET
'
]),
route
(
'
/self/key
'
,
UserHandler
,
h
=
'
generate_api_key
'
,
m
=
[
'
POST
'
]),
route
(
'
/<_id:{uid}>
'
,
UserHandler
),
route
(
'
/<uid:{uid}>/groups
'
,
GroupHandler
,
h
=
'
get_all
'
,
m
=
[
'
GET
'
]),
route
(
'
/<uid:{uid}>/avatar
'
,
UserHandler
,
h
=
'
avatar
'
,
m
=
[
'
GET
'
]),
route
(
'
/<uid:{uid}>/<cont_name:{cname}>
'
,
ContainerHandler
,
h
=
'
get_all_for_user
'
,
m
=
[
'
GET
'
]),
route
(
'
/<_id:{uid}>
'
,
UserHandler
),
route
(
'
/<uid:{uid}>/groups
'
,
GroupHandler
,
h
=
'
get_all
'
,
m
=
[
'
GET
'
]),
route
(
'
/<uid:{uid}>/avatar
'
,
UserHandler
,
h
=
'
avatar
'
,
m
=
[
'
GET
'
]),
route
(
'
/<uid:{uid}>/reset-registration
'
,
UserHandler
,
h
=
'
reset_registration
'
,
m
=
[
'
POST
'
]),
route
(
'
/<uid:{uid}>/<cont_name:{cname}>
'
,
ContainerHandler
,
h
=
'
get_all_for_user
'
,
m
=
[
'
GET
'
]),
]),
...
...
This diff is collapsed.
Click to expand it.
api/auth/__init__.py
+
12
−
0
View file @
1cc1c288
...
...
@@ -55,6 +55,18 @@ def require_login(handler_method):
return
handler_method
(
self
,
*
args
,
**
kwargs
)
return
check_login
def
require_admin
(
handler_method
):
"""
A decorator to ensure the request is made as superuser.
Accepts drone and user requests.
"""
def
check_admin
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
user_is_admin
:
raise
APIPermissionException
(
'
Admin user required.
'
)
return
handler_method
(
self
,
*
args
,
**
kwargs
)
return
check_admin
def
require_superuser
(
handler_method
):
"""
A decorator to ensure the request is made as superuser.
...
...
This diff is collapsed.
Click to expand it.
api/handlers/userhandler.py
+
16
−
1
View file @
1cc1c288
...
...
@@ -7,7 +7,7 @@ from ..web import base
from
..
import
util
from
..
import
config
from
..
import
validators
from
..auth
import
userauth
from
..auth
import
userauth
,
require_admin
from
..dao
import
containerstorage
from
..dao
import
noop
,
APIStorageException
...
...
@@ -177,6 +177,21 @@ class UserHandler(base.RequestHandler):
else
:
self
.
abort
(
500
,
'
New key for user {} not generated
'
.
format
(
self
.
uid
))
@require_admin
def
reset_registration
(
self
,
uid
):
new_registration_code
=
base64
.
urlsafe_b64encode
(
os
.
urandom
(
42
))
update
=
{
'
modified
'
:
datetime
.
datetime
.
utcnow
(),
'
wechat
'
:
{
'
registration_code
'
:
new_registration_code
}
}
result
=
self
.
storage
.
exec_op
(
'
PUT
'
,
_id
=
uid
,
payload
=
update
)
if
result
.
modified_count
==
1
:
return
{
'
registration_code
'
:
new_registration_code
}
else
:
self
.
abort
(
404
,
'
User {} not updated
'
.
format
(
uid
))
def
_get_user
(
self
,
_id
):
user
=
self
.
storage
.
get_container
(
_id
)
if
user
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
api/web/base.py
+
2
−
0
View file @
1cc1c288
...
...
@@ -90,6 +90,8 @@ class RequestHandler(webapp2.RequestHandler):
self
.
abort
(
402
,
'
user account
'
+
self
.
uid
+
'
is disabled
'
)
if
user
.
get
(
'
root
'
):
self
.
user_is_admin
=
True
else
:
self
.
user_is_admin
=
False
if
self
.
is_true
(
'
root
'
):
if
user
.
get
(
'
root
'
):
self
.
superuser_request
=
True
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment