コード例 #1
0
 def post(self):
     #parser = reqparse.RequestParser()
     #parser.add_argument('email', help = 'This field cannot be blank', required = True)
     #data = parser.parse_args()
     data = request.get_json()
     current_user = UserModel.find_by_email(data['email'])
     if not current_user:
         return {
             'message':
             'User whit email {} doesn\'t exist'.format(data['email'])
         }
     else:
         mailTo(username=current_user.username,
                email=data['email'],
                template="resetmail.html")
         return {
             "message":
             "Reset password link was sent to {}".format(data['email'])
         }
コード例 #2
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username',
                            help='This field cannot be blank',
                            required=True)
        parser.add_argument('password',
                            help='This field cannot be blank',
                            required=True)
        parser.add_argument('email')
        data = parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }
        if UserModel.find_by_email(data['email']):
            return {
                'message':
                'An user with email "{}" already exists'.format(data['email'])
            }

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             email=data['email'])
        try:
            new_user.save_to_db()
            #access_token = create_access_token(identity = data['username'])
            #refresh_token = create_refresh_token(identity = data['username'])
            mailTo(username=data['username'],
                   email=data['email'],
                   template="userconfirmation.html")
            return {
                'message':
                'User {} was created, please check your email for varification'
                .format(data['username']),
                #'access_token': access_token,
                #'refresh_token': refresh_token,
            }
        except:
            return {'message': 'Something went wrong'}, 500