def add_user(username, password, email, phone_number): """Inserts new user to the database. Use for register purposes.""" user = User(username=username, password=hash_password(password), email=email, type="user", tags=[], events=[]) if phone_number: user.phone_numer = phone_number user.put()
def remove_token(urlsafe): user = User.get(urlsafe) query = Token.query() query.add_filter('user', '=', user.key) query_list = list(query.fetch()) if query_list: for token_entity in query_list: token_entity.remove()
def get_user_role(urlsafe): user = User.get(urlsafe) if user.type == "user": return Roles.USER if user.type == "admin": return Roles.ADMIN return Roles.NEWBIE
def exists_user(email, password): """Verify if the user exists in the datastore""" query = User.query() query.add_filter('email', '=', email) query_it = query.fetch() for ent in query_it: if ent is None: return None elif check_password(ent.password, password): return ent return None
def get_user(username): """Verify if the user exists in the datastore""" query = User.query() query.add_filter('username', '=', username) query_it = query.fetch() for ent in query_it: if ent is None: return None else: return ent return None
def sendSMSToAllUsers(nrEvents): if nrEvents > 1: allEvents = Event.all() for event in allEvents: if event.title != None and event.date != None and event.location != None: users = User.all() for user in users: if user.phone_number != None: sms.send_sms( user.phone_number, "Did you see the " + event.title + "It's on " + event.date.strftime("%Y-%m-%d %H:%M") + " at " + event.location + "! Join our platform, there are " + str(+nrEvents) + " new events!") return 'Mesaje trimise'
def get(): req = list(RequestDB.all()) if len(req) == 0: return {'status':'204','message': "No requests"} else: last = [] for r in req: cerere = {} cerere['id']=r.urlsafe utilizator= User.get( r.user ) eveniment = Event.get(r.event) cerere['event']=eveniment.title cerere['user']= utilizator.username cerere['field']=r.field cerere['modification']=r.modification cerere['state']=r.state last.append(cerere) return { 'status': '200', 'links':json.dumps(last) }
def remove_event_from_user(user_urlsafe, key): user = User.get(user_urlsafe) if key in user.events: user.events.remove(key) user.put()
def add_event_to_user(user_urlsafe, key): user = User.get(user_urlsafe) if key not in user.events: user.events.append(key) user.put()
def remove_tag_from_user(user_urlsafe, key): user = User.get(user_urlsafe) if key in user.tags: user.tags.remove(key) user.put()
def add_tag_to_user(user_urlsafe, key): user = User.get(user_urlsafe) if key not in user.tags: user.tags.append(key) user.put()
def get_user_events(urlsafe): user = User.get(urlsafe) return user.events
def get_users(): return User.all()
def get_user_tags(urlsafe): user = User.get(urlsafe) return user.tags