Esempio n. 1
0
    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.')
Esempio n. 2
0
    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.')
Esempio n. 3
0
    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.')
Esempio n. 4
0
    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.')