def post(self): research_id = int(request.json['research_id']) research = Research.get(research_id) ResearchIndex(research).put() return ok_msg('Research indexed.')
def put(self, current_user, user): json_request = request.json user.name = json_request.get('name', user.name) user.cv = json_request.get('cv', user.cv) user.put() return ok_msg('Profile updated.')
def post(self, research, user, current_user): relationship = ResearchRelationship.get(research.key, user.email) if not relationship or relationship.type != RelationshipType.WANTS_TO_JOIN: return bad_request('User don\'t want to join.') relationship.type = RelationshipType.REJECTED relationship.put() return ok_msg('Researcher rejected.')
def post(self, current_user, research): relationship = ResearchRelationship.get(research.key, current_user.email) if not relationship or relationship.type != RelationshipType.INVITED: return bad_request('You not invited.') relationship.type = RelationshipType.REJECTED relationship.put() return ok_msg('Invitation rejected.')
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 put(self, current_user): json_request = request.json new_password = json_request['newPassword'] old_password = json_request['oldPassword'] hashed_old_password = hash_password(old_password) if current_user.hashed_password == hashed_old_password: hashed_new_password = hash_password(new_password) current_user.hashed_password = hashed_new_password current_user.put() return ok_msg('Password updated.') else: return bad_request('Incorrect old password.')
def post(self, research, user, current_user): relationship = ResearchRelationship.get(research.key, user.email) if not relationship or relationship.type != RelationshipType.WANTS_TO_JOIN: return bad_request('User don\'t want to join.') research.researchers_keys.append(user.key) research.put() relationship.type = RelationshipType.APPROVED relationship.put() user.researcher_in += 1 user.put() return ok_msg('Researcher accepted.')
def post(self, current_user, research): relationship = ResearchRelationship.get(research.key, current_user.email) if not relationship or relationship.type != RelationshipType.INVITED: return bad_request('You not invited.') research.researchers_keys.append(current_user.key) research.put() relationship.type = RelationshipType.ACCEPTED relationship.put() current_user.researcher_in += 1 current_user.put() return ok_msg('Invitation accepted.')
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 token = json_request['token'] new_password = json_request['newPassword'] change_password = ChangePasswordRequest.by_token(token) if change_password: hashed_new_password = hash_password(new_password) user = change_password.user_key.get() user.hashed_password = hashed_new_password user.put() change_password.key.delete() return ok_msg('Password is reset.') else: return not_found('User didn\'t requested password reset.')
def post(self, research, current_user): recipient = request.json['email'] name = request.json['name'] text = request.json.get('text', '') if self.__relationship_exists(research, recipient): return bad_request('Already invited.') self.__add_relationship(research, recipient) supervisor = current_user.name title = research.title description = research.brief_desc subj_view = InviteToJoinSubj(supervisor, title) body_view = InviteToJoin(supervisor, title, description, name, text) sender.send_email(subj_view, body_view, recipient) return ok_msg("Invitation send to {0}".format(recipient))
def post(self, research, current_user): if self.__relationship_exists(research, current_user.email): return bad_request('Already requested.') self.__add_relationship(research, current_user.email) supervisor = research.supervisor_key.get() user_name = current_user.name recipient = supervisor.email supervisor_name = supervisor.name title = research.title text = request.json.get('text', '') subj_view = ReqToJoinSubj(user_name, title) body_view = ReqToJoin(user_name, title, supervisor_name, text) sender.send_email(subj_view, body_view, recipient) return ok_msg('Request was send to research supervisor.')
def delete(self, research, current_user): research.status = StatusType.DELETED research.put() forums = Forum.by_research2(research.key) for forum in forums: forum.status = StatusType.DELETED forum.put() messages = Message.by_forum2(forum.key) for message in messages: message.status = StatusType.DELETED message.put() ResearchIndex(research).delete() return ok_msg('Research is deleted.')
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 post(self): message_id = int(request.json['message_id']) message = Message.get(message_id) message_creator_key = message.creator_key message_creator = message_creator_key.get() forum = message.forum_key.get() research = forum.research_key.get() for researcher_key in research.researchers_keys: if researcher_key != message_creator_key: researcher = researcher_key.get() subj = NewMessageSubj(forum.subject, research.title) body = NewMessage(researcher.name, message_creator.name, forum.subject, message.text, research.key.id(), forum.key.id()) send_email(subj, body, researcher.email) return ok_msg('Notification sent.')
def delete(self, current_user, message): message.status = StatusType.DELETED message.put() return ok_msg('Message deleted.')
def delete(self, current_user, research, user): self.__delete_relationship(research, user) self.__delete_researcher(research, user) return ok_msg('Researcher removed from research.')
def put(self, current_user, message): message.text = request.json['message'] message.put() return ok_msg('Message updated')
def put(self, current_user, forum): forum.subject = request.json['subject'] forum.put() return ok_msg('Forum is updated.')
def delete(self, current_user, forum): forum.status = StatusType.DELETED forum.put() return ok_msg('Forum is deleted.')
def post(self, current_user): content = request.json['content'] about_page = AboutPage(id=1, content=content) about_page.put() return ok_msg('About page is updated.')