def registration(self, form: RegistrationForm): # регистрация user = User() user.login = form.login.data user.email = form.email.data user.password = form.password.data user.role_id = 2 repeat_password = form.password_again.data if user.password == repeat_password: user.password = generate_password_hash(user.password) try: self.user_resource.post(user) return "" except Exception: return "Такой пользователь уже есть в базе данных" else: return "Пароли не совпадают"
def check_request_user(req, method, user_id=None): # проверяет запрос для пользователей if not req: return jsonify({"error": "Empty request"}) elif not all(key in req for key in ["login", "password", "email", "role_id"]): return jsonify({"error": "Bad request"}) else: user = User() user.login = req["login"] user.password = generate_password_hash(req["password"]) user.email = req["email"] user.role_id = req["role_id"] if method == "post": return jsonify(user_resource.post(user)) elif method == "put": return jsonify(user_resource.put(user_id, user))