def login_admin(request): if request.method == 'POST': body = json.loads(request.body) req = require(body, ['user_name', 'password']) if req: return error(req) body['user_type'] = 'admin' user = user_manager.verify(body) if not user: return error(Error.WRONG_USER_NAME_OR_PASSWORD) access_token = get_admin_access_token({ 'id': user['id'], 'user_name': user['user_name'], 'password': user['password'], 'expiration_date': (datetime.datetime.now() + datetime.timedelta(days=2)).strftime("%Y-%m-%d %H:%M:%S") }) return success({'access_token': access_token})
def get_admin(request, admin_id): if request.method == 'GET': body = get_params(request) req = require(body, ['user_id']) if req: return error(req) user = user_manager.get(body) if not user: return error("can't find this event") return success({'user': user})
def get_by_id(request, user_id): if request.method == 'GET': body = get_params(request) req = require(body, ['event_id']) if req: return error(req) event = event_manager.get(body) if not event: return error("can't find this event") return success({'event': event})
def get_salt(request): if request.method == 'GET': body = get_params(request) req = require(body, ['user_name']) if req: return error(req) body['user_type'] = 'admin' salt = user_manager.get_salt(body) if not salt: return error('can not find this user') return success({'salt': salt})
def create_admin(request): if request.method == 'POST': body = json.loads(request.body) body['user_type'] = 'admin' req = require(body, ['user_name', 'password']) if req: return error(req) if user_manager.check_user_name_is_used(body): return error(Error.USER_NAME_USED) user_manager.create(body) return success({})
def search_by_tag(request, user_id): if request.method == 'GET': body = get_params(request) req = require(body, ['tag_name']) if req: return error(req) events = event_manager.search_by_tag(body) return success({'events': events})
def get_total(request, user_id): if request.method == 'POST': body = json.loads(request.body) req = require(body, ['event_id']) if req: return error(req) total_participant = participant_manager.get_total(body) return success({'total_participant': total_participant})
def get_participant_by_event(request, user_id): if request.method == 'GET': body = get_params(request) req = require(body, ['last_time', 'event_id', 'limit']) if req: return error(req) participants = participant_manager.get_by_event(body) return success({'participants': participants})
def get_like_by_event(request, user_id): if request.method == 'GET': body = get_params(request) req = require(body, ['last_time', 'event_id', 'limit']) if req: return error(req) likes = like_manager.get_by_event(body) return success({'likes': likes})
def create_one_milion_admin(request): if request.method == 'POST': body = json.loads(request.body) for i in range(1000000): body['user_type'] = 'admin' body['user_name'] = id_generator(12, "abcdefghijklmnopqrstuvwxyz") body['password'] = id_generator(12, "abcdefghijklmnopqrstuvwxyz") req = require(body, ['user_name', 'password']) if req: return error(req) if user_manager.check_user_name_is_used(body): return error(Error.USER_NAME_USED) user_manager.create(body) return success({})
def get_participant_by_user(request, user_id): if request.method == 'POST': body = json.loads(request.body) body['user_id'] = user_id req = require(body, ['last_time', 'limit']) if req: return error(req) participants = participant_manager.get_by_user(body) return success({'participants': participants})
def create(request, user_id): if request.method == 'POST' : body = json.loads(request.body) req = require(body, ['content', 'event_id']) if req: return error(req) body['user_id'] = user_id comment_manager.create(body) return success({})
def get_like_by_user(request, user_id): if request.method == 'POST': body = json.loads(request.body) body['user_id'] = user_id req = require(body, ['last_time', 'limit']) if req: return error(req) likes = like_manager.get_by_user(body) return success({'likes': likes})
def get_salt(request): if request.method == 'GET': body = get_params(request) req = require(body, ['user_name']) if req: return error(req) body['user_type'] = 'visitor' salt = user_manager.get_salt(body) return success({'salt': salt})
def refresh_token(request): if request.method == 'GET': body = get_params(request) req = require(body, ['access_token']) if req: return error(req) access_token = body['access_token'] data_user = json.loads( json.dumps( jwt.decode(access_token, Config.SECRET_KEY_VISITOR, algorithms=['HS256']))) print(data_user) data_user['user_type'] = 'visitor' user = user_manager.verify(data_user) if not user: return error(Error.WRONG_USER_NAME_OR_PASSWORD) new_access_token = get_visitor_access_token({ 'id': user['id'], 'user_name': user['user_name'], 'password': user['password'], 'expiration_date': (datetime.datetime.now() + datetime.timedelta(days=2)).strftime("%Y-%m-%d %H:%M:%S") }) return success({'new_access_token': new_access_token})