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
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)
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
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)
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()
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
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)
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
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)
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
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]
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)
def get(self): cliams = get_jwt_claims() return cliams return userListSchema.dump(UserModel.fetchAll())
def delete(self, userid): user = UserModel.findById(userid) if user is not None: user.delete() return userschema.dump(user) return log.ISNOTEXIST(), 404
def get(cls): user = UserModel.fetchAll() alluser = UserSchema(many=True).dump(user) return {'data': alluser[0]}
def get(self, userid): user = UserModel.findById(userid) if user is None: return gettex('NOT_FOUND'), 400 return UserSchema().dump(user)