forked from YoLoveLife/DevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yo
committed
Oct 31, 2018
1 parent
5a2f075
commit 693fd8c
Showing
15 changed files
with
59 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# -*- coding:utf-8 -*- | ||
# !/usr/bin/env python | ||
# Time 17-10-25 | ||
# Author Yo | ||
# Email [email protected] | ||
import pyotp | ||
import os | ||
from qrcode import QRCode, constants | ||
|
@@ -13,13 +17,13 @@ | |
from deveops.utils import aes | ||
from authority.permission import user as UserPermission | ||
from timeline.decorator import decorator_api | ||
from .. import models,serializers,filter | ||
from .. import models, serializers, filter | ||
|
||
__all__ = [ | ||
"UserLoginAPI", "UserInfoAPI", "UserListAPI", | ||
"UserOpsListAPI", "UserUpdateAPI", "UserDeleteAPI", | ||
"UserListByPageAPI", 'UserPagination', 'UserOpsListByPageAPI', | ||
'UserQRCodeAPI', 'UserCreateAPI', | ||
'UserQRCodeAPI', 'UserCreateAPI', 'UserExpireAPI' | ||
] | ||
|
||
|
||
|
@@ -96,18 +100,17 @@ class UserCreateAPI(WebTokenAuthentication, generics.CreateAPIView): | |
@decorator_api(timeline_type=settings.TIMELINE_KEY_VALUE['ExtendUser_USER_CREATE']) | ||
def create(self, request, *args, **kwargs): | ||
if self.qrcode_check(request): | ||
request.data.pop('qrcode') | ||
response = super(UserCreateAPI, self).create(request, *args, **kwargs) | ||
return self.msg.format( | ||
USER = request.user.full_name, | ||
USERNAME = response.data['username'], | ||
FULLNAME = response.data['full_name'], | ||
USER=request.user.full_name, | ||
USERNAME=response.data['username'], | ||
FULLNAME=response.data['full_name'], | ||
), response | ||
else: | ||
return '', self.qrcode_response | ||
|
||
|
||
class UserUpdateAPI(WebTokenAuthentication,generics.UpdateAPIView): | ||
class UserUpdateAPI(WebTokenAuthentication, generics.UpdateAPIView): | ||
module = models.ExtendUser | ||
serializer_class = serializers.UserSerializer | ||
queryset = models.ExtendUser.objects.all() | ||
|
@@ -117,7 +120,6 @@ class UserUpdateAPI(WebTokenAuthentication,generics.UpdateAPIView): | |
@decorator_api(timeline_type=settings.TIMELINE_KEY_VALUE['ExtendUser_USER_UPDATE']) | ||
def update(self, request, *args, **kwargs): | ||
if self.qrcode_check(request): | ||
request.data.pop('qrcode') | ||
response = super(UserUpdateAPI, self).update(request, *args, **kwargs) | ||
user = self.get_object() | ||
return self.msg.format( | ||
|
@@ -139,7 +141,6 @@ class UserDeleteAPI(WebTokenAuthentication,generics.DestroyAPIView): | |
@decorator_api(timeline_type=settings.TIMELINE_KEY_VALUE['ExtendUser_USER_DELETE']) | ||
def delete(self, request, *args, **kwargs): | ||
if self.qrcode_check(request): | ||
request.data.pop('qrcode') | ||
user = self.get_object() | ||
response = super(UserDeleteAPI, self).delete(request, *args, **kwargs) | ||
return self.msg.format( | ||
|
@@ -152,14 +153,13 @@ def delete(self, request, *args, **kwargs): | |
|
||
|
||
def get_qrcode(user): | ||
if not user.qrcode: # '' | ||
if not user.qrcode: | ||
user.qrcode = pyotp.random_base32() | ||
user.save() | ||
file_name = str(aes.encrypt(user.qrcode),encoding='utf-8') | ||
file_name = str(aes.encrypt(user.qrcode), encoding='utf-8') | ||
file = settings.QCODE_ROOT+'/'+file_name+'.png' | ||
if not os.path.exists(file): | ||
data = pyotp.totp.TOTP(user.qrcode).provisioning_uri(user.username, issuer_name="devEops") | ||
print('data',data) | ||
qr = QRCode( | ||
version=1, | ||
error_correction=constants.ERROR_CORRECT_L, | ||
|
@@ -170,9 +170,9 @@ def get_qrcode(user): | |
qr.make(fit=True) | ||
img = qr.make_image() | ||
img.save(file) | ||
return '/media/qrcode/'+ file_name +'.png' | ||
return '/media/qrcode/' + file_name + '.png' | ||
except Exception as e: | ||
return '/media/qrcode/'+ file_name +'.png' | ||
return '/media/qrcode/' + file_name + '.png' | ||
else: | ||
return '/media/qrcode/' + file_name + '.png' | ||
|
||
|
@@ -198,3 +198,12 @@ def get(self, request, *args, **kwargs): | |
return '', Response({ | ||
'detail': settings.LANGUAGE.UserQRCodeAPIHaveQRCode | ||
}, status=status.HTTP_406_NOT_ACCEPTABLE) | ||
|
||
|
||
class UserExpireAPI(WebTokenAuthentication, APIView): | ||
permission_classes = [IsAuthenticated, ] | ||
|
||
def get(self, request, *args, **kwargs): | ||
return Response({ | ||
'isexpire': request.user.is_expire | ||
}, status=status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
# Time 18-6-7 | ||
# Author Yo | ||
# Email [email protected] | ||
import django_filters | ||
from manager import models | ||
from django.contrib.auth.models import Permission,Group | ||
from django.db.models import Q | ||
import django_filters | ||
from manager import models | ||
|
||
__all__ = [ | ||
'UserFilter', 'GroupFilter', 'KeyFilter', 'JumperFilter' | ||
|
@@ -18,6 +18,7 @@ class UserFilter(django_filters.FilterSet): | |
name = django_filters.CharFilter(method="name_filter") | ||
username = django_filters.CharFilter(method="username_filter") | ||
is_active = django_filters.CharFilter(method="is_active_filter") | ||
|
||
class Meta: | ||
model = models.ExtendUser | ||
fields = ['phone', 'name', 'username', 'email', 'is_active'] | ||
|
@@ -42,6 +43,7 @@ def is_active_filter(queryset, first_name, value): | |
class GroupFilter(django_filters.FilterSet): | ||
permission = django_filters.CharFilter(method="permission_filter") | ||
name = django_filters.CharFilter(method="name_filter") | ||
|
||
class Meta: | ||
model = Group | ||
fields = ['permission', 'name'] | ||
|
@@ -59,9 +61,10 @@ def name_filter(queryset, first_name, value): | |
class KeyFilter(django_filters.FilterSet): | ||
name = django_filters.CharFilter(method="name_filter") | ||
group_name = django_filters.CharFilter(method="group_name_filter") | ||
|
||
class Meta: | ||
model = models.Key | ||
fields = ['name',] | ||
fields = ['name', ] | ||
|
||
@staticmethod | ||
def name_filter(queryset, first_name, value): | ||
|
@@ -76,6 +79,7 @@ def group_name_filter(queryset, first_name, value): | |
class JumperFilter(django_filters.FilterSet): | ||
info = django_filters.CharFilter(method="info_filter") | ||
group_name = django_filters.CharFilter(method="group_name_filter") | ||
|
||
class Meta: | ||
model = models.Jumper | ||
fields = ['info', 'group_name'] | ||
|
@@ -87,4 +91,4 @@ def info_filter(queryset, first_name, value): | |
@staticmethod | ||
def group_name_filter(queryset, first_name, value): | ||
groups = models.Group.objects.filter(name__icontains=value) | ||
return queryset.filter(group__in=groups) | ||
return queryset.filter(group__in=groups) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,15 @@ | |
# Time 17-10-25 | ||
# Author Yo | ||
# Email [email protected] | ||
from __future__ import absolute_import, unicode_literals | ||
from celery import Task,task | ||
import socket, paramiko, os, stat, time | ||
import socket | ||
import paramiko | ||
import os | ||
import stat | ||
import time | ||
from django.conf import settings | ||
from celery import Task, task | ||
|
||
|
||
class JumperTask(Task): | ||
def on_failure(self, exc, task_id, args, kwargs, einfo): | ||
print('{0!r} failed: {1!r}'.format(task_id, exc)) | ||
|
@@ -70,4 +75,4 @@ def jumper_status_flush(obj): | |
return | ||
|
||
obj._status = settings.STATUS_JUMPER_CAN_BE_USE | ||
obj.save() | ||
obj.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# from django.conf.urls import path | ||
# -*- coding:utf-8 -*- | ||
# !/usr/bin/env python | ||
# Time 17-10-25 | ||
# Author Yo | ||
# Email [email protected] | ||
from django.urls import path | ||
from ..api import user | ||
from ..api import group | ||
from ..api import permission | ||
from ..api import key | ||
from ..api import jumper | ||
|
||
urlpatterns = [ | ||
# Resource login api | ||
path(r'login/', user.UserLoginAPI.as_view()), | ||
|
@@ -19,6 +24,7 @@ | |
path(r'v1/user/<int:pk>/update/', user.UserUpdateAPI.as_view()), | ||
path(r'v1/user/<int:pk>/delete/', user.UserDeleteAPI.as_view()), | ||
path(r'v1/user/qrcode/', user.UserQRCodeAPI.as_view()), | ||
path(r'v1/user/expire/', user.UserExpireAPI.as_view()), | ||
# | ||
# Resource group api | ||
path(r'v1/group/', group.GroupListAPI.as_view()), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.