Exemplo n.º 1
0
    def post(self):
        value = request.get_json()
        value.update({'registerDate': int(time())})

        user = userschema.load(value)
        isName = UserModel.findByName(user.name)
        isEmail = UserModel.findByEmail(user.email)

        if isName is None and isEmail is None:
            user.insert()  # savetodatabase
            confirm = ConfirmationModel(user.userId)
            confirm.insert()
            user.sendMsg()
            return userschema.dump(user)
        return log.ISEXIST(), 400
Exemplo n.º 2
0
    def post(self):
        value = req.get_json()
        value.update({'userId': uuid4().hex})
        user = UserSchema().load(value, session=db.session)
        isEmail = bool(UserModel.findByEmail(user.email))
        isName = bool(UserModel.findByName(user.name))

        if isEmail or isName:
            return gettex('EXIST'), 422
        try:
            user.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
Exemplo n.º 3
0
    def post(cls):
        value = parser.parse_args()
        user = UserModel.findByEmail(value.email)
        if user and safe_str_cmp(user.password, value.password):
            return cls.newToken(user)

        return gettex('NOT_FOUND'), 400
Exemplo n.º 4
0
    def post(cls):
        data = req.get_json()
        store = StoreSchema().load(data, partial=('storeId', ))
        try:
            isExist = StoreModel.findByStoreName(data['storeName'])
            user = UserModel.findById(data['userId'])
            islimit = StoreModel.isLimit(data['userId'])
        except:
            return gettex('SOMETHING_WRONG'), 500

        if bool(isExist):
            return gettex('EXIST'), 422

        if not bool(user):
            return gettex('NOT_EXIST'), 404

        if islimit:
            return gettex('LIMITED'), 422

        try:
            storeId = f"ST_{store.findSerial() + 1}_{int(time())}_{user.userId}"
            store.storeId = storeId
            store.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return StoreSchema().dump(store)
Exemplo n.º 5
0
    def post(cls,userid:int):
        user = UserModel.findById(userid)
        if user is not None:
            confrimate = ConfirmationModel(user.userId)
            confrimate.insert()
            user.sendMsg() 
            return gettext('emailSent').format(user.email)

        return log.ISNOTEXIST()
Exemplo n.º 6
0
 def put(self, userid):
     value = request.get_json()
     user = UserModel.findById(userid)
     if user is not None:
         user.name = value['name']
         user.email = value['email']
         user.insert()
         return userschema.dump(user)
     return log.ISNOTEXIST(), 404
Exemplo n.º 7
0
    def delete(self, userid):
        user = UserModel.findById(userid)
        if user is None:
            return gettex('NOT_FOUND'), 400
        try:
            user.delete()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
Exemplo n.º 8
0
    def post(self):
        value = request.get_json()
        values = userschema.load(value,partial = ('registerDate','name',))
        user = UserModel.findByEmail(values.email)
        if user and safe_str_cmp(user.password,values.password):
            confirmation = user.recentConfirmation
            if confirmation and confirmation.confirmed: # if activated
                return self.generateToken(user.userId)

            # do an activate user
            return gettext('emailNotConfirm').format(user.email)
        return log.ISNOTEXIST(),404
Exemplo n.º 9
0
    def put(self):
        userid = get_jwt_claims()['userId']
        value = req.get_json()
        user = UserModel.findById(userid)
        if not bool(user):
            return gettex('NOT_FOUND'), 400

        try:
            user.name = value['name']
            user.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
Exemplo n.º 10
0
def get_salt_users():
    sql = 'select * from PiptUser JOIN Investigator using (Investigator_Id)'
    conn = sdb_connect()
    results = pd.read_sql(sql, conn)
    conn.close()
    users = []
    for index, row in results.iterrows():
        if row["Username"] is not None:
            users.append(
                UserModel(username=row["Username"],
                          first_name=row["FirstName"],
                          last_name=row["Surname"],
                          email=row["Email"],
                          role=[]))

    return users
Exemplo n.º 11
0
def get_user(user_id):
    user = {}

    sql = " select *, t.PiptUser_Id as Tac, t.Partner_Id as TacPartner, a.Investigator_Id as Astro " \
          " from PiptUser as u " \
          " JOIN Investigator as i using (Investigator_Id) " \
          " left join SaltAstronomers as a using( Investigator_Id ) " \
          " left join PiptUserTAC as t on (u.PiptUser_Id = t.PiptUser_Id) " \
          " where u.PiptUser_Id = {user_id}".format(user_id=user_id)
    conn = sdb_connect()
    results = pd.read_sql(sql, conn)
    conn.close()
    username = ''
    for index, row in results.iterrows():
        username = row["Username"]
        if username not in user:
            user[username] = UserModel(username=row["Username"],
                                       first_name=row["FirstName"],
                                       last_name=row["Surname"],
                                       email=row["Email"],
                                       role=[])
        user[username].role += get_role(row, user_id)
    return user[username]
Exemplo n.º 12
0
    def get(cls):
        params = request.args
        res = github.authorized_response()

        if res is None or res.get('access_token') is None:
            return {
                "error": params['error'],
            }

        g.access_token = res['access_token']
        github_user = github.get('user')
        value = {
            "email": github_user.data['email'],
            "name": github_user.data['login'],
            "registerDate": int(time())
        }

        user = UserModel.findByEmail(value['email'])
        if user is not None:
            return Authenticate.generateToken(user.userId)

        newuser = userschema.load(value, partial=('password', ))
        newuser.insert()
        return Authenticate.generateToken(newuser.userId)
Exemplo n.º 13
0
    def get(self):

        cliams = get_jwt_claims()
        return cliams
        return userListSchema.dump(UserModel.fetchAll())
Exemplo n.º 14
0
 def delete(self, userid):
     user = UserModel.findById(userid)
     if user is not None:
         user.delete()
         return userschema.dump(user)
     return log.ISNOTEXIST(), 404
Exemplo n.º 15
0
    def get(cls):

        user = UserModel.fetchAll()
        alluser = UserSchema(many=True).dump(user)
        return {'data': alluser[0]}
Exemplo n.º 16
0
    def get(self, userid):
        user = UserModel.findById(userid)
        if user is None:
            return gettex('NOT_FOUND'), 400

        return UserSchema().dump(user)