コード例 #1
0
 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 "Пароли не совпадают"
コード例 #2
0
ファイル: api.py プロジェクト: fearppen/CinemaSystem
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))
コード例 #3
0
    def update_user_and_get(self, github_token, flask_global):
        request_user = User()
        request_user.access_token = github_token

        flask_global.user = request_user
        github_user = self.github.get('/user')
        github_id = github_user['id']

        user = User.query.filter_by(github_id=github_id).first()
        if user is None:
            user = User()
            user.github_id = github_id
            user.login = github_user['login']
            self.db_session.add(user)

        user.access_token = github_token
        self.db_session.commit()

        return user