def get(self, current_user): cursor = request.args.get('cursor') keyword = request.args.get('keyword') users, cursor, _ = User.find_all(cursor, keyword) return ok(ListUsers(users, cursor))
def create(nickname, phone, password): password_hash = generate_password_hash(password) user = { "nickname": nickname, "phone": phone, "password_hash": password_hash, } db.session.add(User(**user)) db.session.commit()
def post(self): email = request.json['email'] hashed_pass = hash_password(request.json['password']) user = User.by_email_and_password(email, hashed_pass) if not user: return unauthorized('User not found.') return ok(Token(user.key.id()).json())
def post(self): json_request = request.json email = json_request['email'] name = json_request['name'] password = json_request['password'] cv = json_request.get('cv', '') user = User.by_email(email) if user: return bad_request('User with email {0} already exists'.format(email)) user = User(name=name, email=email, cv=cv, is_admin=False, status=StatusType.ACTIVE, hashed_password=hash_password(password)) user_key = user.put() return created(Token(user_key.id()).json())
def put(self, current_user, research): new_supervisor_email = request.json['new_supervisor'] supervisor = User.by_email(new_supervisor_email) if not supervisor: return not_found('User with email not found.') self.__delete_relationship(research, research.supervisor_key.get()) research.supervisor_key = supervisor.key research.put() self.__add_relationship(research.key, supervisor) return ok_msg('Supervisor is updated.')
def wrapper(*args, **kwargs): if 'user_id' not in kwargs: return bad_request('To use insert_user wrapper user_id must be in url.') _id = kwargs['user_id'] user = User.get(int(_id)) if user is None: return user_not_found(_id) del kwargs['user_id'] kwargs['user'] = user return func(*args, **kwargs)
def post(self, current_user, research): researcher_email = request.json['new_researcher'] researcher = User.by_email(researcher_email) if not researcher: return not_found('User with email not found.') if researcher.key in research.researchers_keys \ or research.supervisor_key == researcher.key: return bad_request('User already is researcher.') research.researchers_keys.append(researcher.key) research.put() self.__add_relationship(research.key, researcher_email) return ok_msg('Researcher is added.')
def post(self): json_request = request.json email = json_request['email'] user = User.by_email(email) if user: token = str(uuid.uuid4()) base_url = os.environ['BASE_UI_URL'] url = base_url + '/forgot-password/' + token user_name = user.name ChangePasswordRequest(user_key=user.key, token=token).put() subj = ResetPasswordSubj(user_name) body = ResetPasswordBody(user_name, url) sender.send_email(subj, body, email) return ok_msg('Emails with instructions is sent.') else: return not_found('User not found in system.')
def wrapper(*args, **kwargs): if 'Authorization' not in request.headers: kwargs['current_user'] = None return func(*args, **kwargs) authorization = request.headers['Authorization'] token = authorization.replace('Bearer ', '') try: user_id = TOKEN_UTIL.verify(token) except SignatureExpired: return unauthorized('Token expired.') except BadSignature: return unauthorized('Invalid token.') user = User.get(int(user_id)) if not user: return unauthorized('User not found.') kwargs['current_user'] = user return func(*args, **kwargs)
def signup(): if request.method == 'GET': print 'dans signup get' return render_template('signup.html') elif request.method == 'POST': try: print 'dans signup try' mylogin = User() mylogin.pseudo = request.form['pseudo'] mylogin.password = request.form['password'] print request.form['pseudo'] print request.form['password'] mylogin.save() except: print 'dans signup except' flash('oops', 'danger') return redirect(url_for('signup')) else: print 'dans signup else' login_user(mylogin) flash("Bonjour " + current_user.pseudo + ", voici vos taches !", 'success') return redirect(url_for('list'))
def get(self, research, current_user): relationships = ResearchRelationship.by_research_and_type(research.key, RelationshipType.WANTS_TO_JOIN) users = map(lambda r: User.by_email(r.user_email), relationships) return ok(ListReqToJoin(users).js())
def update_users_status(users_ids, status, update_forums, update_messages): for user_id in users_ids: user = User.get(user_id) update_user_status(user, status, update_forums, update_messages)