コード例 #1
0
ファイル: auth.py プロジェクト: matran/scan2shop-service
import secrets
from sqlalchemy.sql import func
from sqlalchemy.sql.expression import text
from datetime import datetime, timedelta
from flask import current_app
from flask_restful import Api
from flask import flash
from flask import url_for
from flask import jsonify
from forms import ResetPasswordForm
from flask import render_template,make_response
from Model import db, Users,UserSchema,PasswordChange
from werkzeug.security import generate_password_hash,check_password_hash
from werkzeug.utils import secure_filename
import os
user_schema = UserSchema()
users_schema=UserSchema(many=True)
app = Flask(__name__)
app.config.from_object('config')
mail = Mail()
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
class AuthUsersResource(Resource):
    def post(self):
        json_data = request.get_json(force=True)
        if not json_data:
               return {'status':'fail','message': 'No input data provided'}, 200
        user = Users.query.filter_by(email=json_data['email']).first()
        if user:
            return {'status':'fail','message': 'User already exists'}, 200
        user = Users(
            firstname=json_data['firstname'],
コード例 #2
0
#
#
#
#

from flask_restful import Resource
from flask import request, jsonify, make_response
from Model import db, User, UserSchema, Contact, ContactSchema
import uuid
from werkzeug.security import generate_password_hash, check_password_hash
import jwt
import datetime
import time
from functools import wraps

users_schema = UserSchema(many=True)  # to GET all users
user_schema = UserSchema()  # accessing one user to POST

contacts_schema = ContactSchema(many=True)  # to GET all users
contact_schema = ContactSchema()  # accessing one user to POST


# this is the decorator definition that requires a token for all api requests
def token_required(f):
    # defines this func as 'wrapping' f
    @wraps(f)
    def decorated(*args, **kwargs):
        # add token from request header
        token = None
        if 'x-access-token' in request.headers:
            token = request.headers['x-access-token']
コード例 #3
0
from flask_restful import Resource
from flask import request
from Model import db, User, UserSchema
import random
import string

user_schema = UserSchema()

class Register(Resource):
    def get(self):
        users = User.query.all()
        user_list = []
        for i in range(len(users)):
            user_list.append(users[i].serialize())
        return {"status" : "Success", "Users" : user_list }

    def post(self):
        json_data = request.get_json(force=True)

        #Check if data exists 
        if not json_data:
               return {'message': 'No input data provided'}, 400

        # Validate and deserialize input
        data, errors = user_schema.load(json_data)
        if errors:
            return errors, 422

        # See if a user already exists 
        user = User.query.filter_by(username=data['username']).first()
        if user:
コード例 #4
0
ファイル: User.py プロジェクト: lemonad/500weeks
from flask import request
from flask_restful import Resource
from Model import db, User as User, UserSchema

user_schema_many = UserSchema(many=True)
user_schema = UserSchema()


class UserResource(Resource):
    def get(self, username):
        user = User.query.filter_by(username=username).first_or_404()
        return (
            {
                "username": user.username,
                "first_name": user.first_name,
                "last_name": user.last_name,
            },
            200,
        )

    def put(self, username):
        json_data = request.get_json(force=True)
        if not json_data:
            return {"message": "No input data provided"}, 400
        # Validate and deserialize input
        data, errors = user_schema.load(json_data)
        if errors:
            return errors, 422
        user = User.query.filter_by(username=data["username"]).first()
        if not user:
            return {"message": "User does not exist"}, 400