def login(request, data): pwd = str_utils.generate_sha1(data["password"]) success = user_manager.login(data["name"], pwd) if success: user = user_manager.load_user(data["name"]) user["token"] = token_manager.generate_token(user) return defs.response_data(Resp.RESP_OK, user) else: return defs.response_data(Resp.RESP_LOGIN_FAILED, msg="登录用户名或者密码错误")
def login(request, data): pwd = str_utils.generate_sha1(data["password"]) success = user_manager.login(data["name"], pwd) if success: user = user_manager.load_user(data["name"]) user["token"] = token_manager.generate_token(user, True) return defs.response_data(Resp.RESP_OK, user) raise BusinessExceptionError(Resp.RESP_LOGIN_FAILED)
def process_request(self, request): if request.method == 'OPTIONS': return HttpResponse() if Authentication.not_need_login(request): return None is_admin = request.path.startswith(ADMIN_DIR) validate_token, validate_message = token_manager.validate_token(request, is_admin) if validate_token: return None if validate_message is not None: return defs.response_data(Resp.RESP_NOT_LOGGED_IN, msg=validate_message) else: return HttpResponse(status=401)
def channel_edit(request, data): resp, model, old_name = activity_channel_manager.edit(request.user, **data) if not old_name: activity_manager.update_channel(old_name, model.get('name')) return defs.response_data(resp, model)
def channel_remove(request, data): resp = activity_channel_manager.remove(request.user, **data) return defs.response_data(resp)
def channel_add(request, data): resp, model = activity_channel_manager.add(request.user, **data) return defs.response_data(resp, model)
def activity_remove(request, data): resp = activity_manager.remove(user=request.user, **data) return defs.response_data(resp)
def activity_edit(request, data): resp, model = activity_manager.edit(request.user, **data) return defs.response_data(resp, model)
def send_email(request, data): send_email_task.send_email_to_user.delay(**data) return defs.response_data(Resp.RESP_OK)
def get_detail(request, data): activity_id = data.get('activity_id') activity = activity_manager.get_activity(activity_id) return defs.response_data(Resp.RESP_OK, activity)
def comment_add(request, data): resp, model = activity_manager.comment_add(user=request.user, **data) return defs.response_data(resp, model)
def enter_cancel(request, data): resp = activity_manager.enter_cancel(user=request.user, **data) return defs.response_data(resp)