def post(self): flow = app.flow flow.redirect_uri = request.form["redirect_uri"] authCode = request.form["code"] flow.fetch_token(code=authCode) credentials = flow.credentials req_url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + credentials.token user_info = requests.get(req_url).json() user = AuthenticationService.getUser(email=user_info['email']) if user: if not user.password: sessionId = uuid4() session = Session(user=user, sessionId=sessionId) session.save() ret = make_response(user_info) ret.set_cookie("SID", str(session.sessionId), expires=session.dateExpires) return ret return Response("Email already registered with our service", status=403) else: ret = {} ret['message'] = "Redirect to complete sign up" ret['user'] = user_info return Response(ret, status=200)
def createDatasetInfoObject(self, dataset, withHeaders=False): datasetAuthor = AuthenticationService.getUser(id=dataset.author.id) datasetInfoObject = { "name": dataset.name, "legend": dataset.legend, "type": dataset.datasetType, "author": datasetAuthor.getFullname(), "tags": dataset.tags, "id": str(dataset.id), "views": dataset.views } if (withHeaders): headers = [] #v-table requires headers to be in this format #TODO: Update v-table so that we can just pass the headers in as normal without performing any extra work for header in dataset["keys"]: headerObj = {"text": header, "value": header} headers.append(headerObj) datasetInfoObject["headers"] = headers return datasetInfoObject
def post(self): try: user = AuthenticationService.getUser(email=request.form["email"]) passwordResetId = uuid4() AuthenticationService.setUserResetID(user, passwordResetId) try: subject = "Reset Password" html = f"<p>We heard you lost your password. No worries, just click the link below to reset your password.</p><p>You can safely ignore this email if you did not request a password reset</p><br/><a href=\"{app.rootUrl}/reset-password/{passwordResetId}\"> Reset password </a><br/>" MailService.sendMessage(user, subject, html) return Response( "An email with instructions to reset your password has been sent to the provided email.", status=200) except: return Response( "Unable to send password reset email. Please try again later.", status=400) except: return Response( "No account with given email found. Please try creating a new account.", status=403)