def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": gettext("confirmation_not_found")}, 404 if confirmation.expired: headers = {"Content-Type": "text/html"} return make_response( render_template( "resend_activation_link_page.html", EXPIRED=gettext("confirmation_expired"), user_id=confirmation.user.id, ), 200, headers, ) if confirmation.confirmed: return {"message": gettext("confirmation_already_confirmed")}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, headers, )
def get(cls, confirmation_id: str): """Return confirmation html page""" confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": gettext("confirmation_not_found")}, 404 if confirmation.expired: return {"message": gettext("confirmation_link_expired")}, 400 if confirmation.confirmed: return {"message": gettext("confirmation_already_confirmed")}, 400 confirmation.confirmed = True confirmation.save_to_db() user = UserModel.find_by_id(confirmation.user_id) headers = { "Content-Type": "text/html" } return make_response( render_template("confirmation_page.html", email=user.email), 200, headers )
def post(cls): """Confirm registration""" confirmation_data = request.get_json() confirmation_id = confirmation_data['confirmation_id'] confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return { "message": gettext("confirmation_not_found"), 'status': 404 } if confirmation.expired: return { "message": gettext("confirmation_link_expired"), 'status': 404 } if confirmation.confirmed: return { "message": gettext("confirmation_already_confirmed"), 'status': 404 } confirmation.confirmed = True try: confirmation.save_to_db() session['message_success'] = gettext("user_logged_in").format( confirmation.user.username) login_user(confirmation.user) return {'status': 200} except: confirmation.confirmed = False return { "message": gettext("confirmation_confirm_error"), 'status': 500 }
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) user = CustomerModel.find_by_id(confirmation.customer_id) if not user: return {"message": CUSTOMER_NOT_FOUND}, 404 confirmation.confirmed = True confirmation.save_to_db() headers = {"Context-Type": "text/html"} return make_response(render_template("confirmed.html"), 200, headers)
def get(cls, confirmation_id): """User registration confirmation page""" link = request.url_root[:-1] + url_for( "confirmationpage", confirmation_id=confirmation_id) # create confirmation link confirmation = ConfirmationModel.find_by_id(confirmation_id) email = confirmation.user.email return Response( render_template('user/confirmation.html', confirmation_id=confirmation_id, link=link, email=email))
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"Message": NOT_FOUND_ERROR} if confirmation.expired: return {"message": LINK_EXPIRED_ERROR} if confirmation.is_confirmed: return {"Message": ALREADY_CONFIRMED_INFO} confirmation.is_confirmed = True confirmation.insert_in_db() return {"Message": "success"}
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"Message": gettext("confirmation_token_not_found")} if confirmation.expired: return {"Message": gettext("confirmation_token_expired")} if confirmation.is_confirmed: return {"Message": gettext("confirmation_already_confirmed")} confirmation.is_confirmed = True confirmation.insert_in_db() return {"Message": gettext("confirmation_successful")}
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": CONFIRMATION_NOT_FOUND}, 404 if confirmation.expired: return {"message": CONFIRMATION_EXPIRED}, 400 if confirmation.confirmed: return {"message": CONFIRMATION_ALREADY_CONFIRMED}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return make_response(render_template("confirmed.html"), 200, headers)
def get(cls, confirmation_id: str): """Return confirmation HTML page.""" confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": CONFIRMATION_NOT_FOUND}, 404 if confirmation.expired: return {"message": CONFIRMATION_EXPIRED}, 400 if confirmation.confirmed: return {"message": CONFIRMATION_ALREADY_CONFIRMED}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return {"message": USER_CONFIRMED}, 200
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": gettext("confirmation_not_found")}, 404 if confirmation.expired: return {"message": gettext("confirmation_link_expired")}, 400 if confirmation.confirmed: return {"message": gettext("confirmation_already_confirmed")}, 400 confirmation.confirmed = True confirmation.save_to_db() return redirect(os.environ.get("CLIENT_URL") + "/confirmed", code=302)
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {'message': NOT_FOUND}, 404 if confirmation.expired: return {'message': EXPIRED}, 400 if confirmation.confirmed: return {'message': ALREADY_CONFIRMED}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {"content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, headers)
def get(self, confirmation_id): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": "Not found Confirmation"}, 404 if confirmation.expired: return {"message": "Confirmation is Already expired"}, 400 if confirmation.confirmed: return {"message": "Confirmation is Already confirmed"}, 400 confirmation.confirmed = True confirmation.save_database() headers = {"Content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, headers)
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {'message': gettext("confirmation_not_found")}, 400 if confirmation.expired: return {'message': gettext("confirmation_expired")}, 400 if confirmation.confirmed: return {'message': gettext("confirmation_already_confirmed")}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {'Content-Type': 'text/html'} return make_response( render_template('confirmation_page.html', email=confirmation.user.email), 200, headers)
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: # does not exist return {"message": gettext('confirmation_not_found')}, 404 if confirmation.expired: # has expired return {"message": gettext('confirmation_link_expired')} if confirmation.confirmed: # is confirmed return {"message": gettext('confirmation_already_confirmed')} confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=confirmation.user.username), 200, headers)
def get(cls, confirmation_id: int): """Return confirmation HTML page""" confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": gettext("confirmation_not_found")}, 404 if confirmation.expired: return {"message": gettext("confirmation_expired")}, 400 if confirmation.confirmed: return {"message": gettext("confirmation_already_confirmed")}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} # return {"message": USER_CONFIRMED}, 200 return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, headers)
def get(cls, confirmation_id: str): """ Returns confirmation HTML Page """ confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": "Confirmation reference not found."}, 404 if confirmation.expired: return {"message": "The link has expired."}, 400 if confirmation.confirmed: return {"message": "Registration has already been confirmed."}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, headers)
def get(cls, confirmation_id: str): """Return confirmation HTML""" confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {'message': gettext('confirmation_not_found')}, 404 if confirmation.expired: return {'message': gettext('confirmation_link_expired')}, 400 if confirmation.confirmed: return {'message': gettext('confirmation_already_confirmed')}, 400 confirmation.confirmed = True confirmation.save_to_db() headers = { 'Content-Type': 'text/html' } # by default the type is Json, and here we send HTML, so we need to declare it as text return make_response( render_template('confirmation_page.html', email=confirmation.user.email), 200, headers)
def get(cls, confirmation_id: str): """Return confirmation HTML information""" confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {'message': "not found"}, 404 elif confirmation.expired: return {'message': "already expired"}, 400 elif confirmation.confirmed: return {'message': "already confirmed"}, 400 confirmation.confirmed = True confirmation.save_to_db() header = {'Content-Type': 'text/html'} return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, header)
def get(cls, confirmation_id: str): """Return confirmation HTML page""" confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": (gettext("confirmation_NOT_FOUND"))}, 404 if confirmation.expired: return {"message": (gettext("confirmation_EXPIRED"))}, 400 if confirmation.confirmed: return { "message": (gettext("confirmation_ALREADY_CONFIRMED")) }, 400 confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, headers, )
def get(cls, confirmation_id: str): confirmation = ConfirmationModel.find_by_id(confirmation_id) if not confirmation: return {"message": "Confirmation not found"}, 404 if confirmation.expired: return {"message": "confirmation expired"}, 400 if confirmation.confirmed: return {"message": "already confirmed"} confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=Confirmation.user.email), 200, headers, )
def get(cls, confirmation_id: str): """ Return confirmation HTML page """ confirmation = ConfirmationModel.find_by_id(confirmation_id) error_msg = (False, 400) headers = {"Content-Type": "text/html"} if not confirmation: error_msg = msgs.NOT_FOUND, 404 elif confirmation.confirmed: error_msg = msgs.ALREADY_CONFIRMED, 400 elif confirmation.expired: error_msg = msgs.EXPIRED, 400 if error_msg[0]: return make_response( render_template("confirmation_error_page.html", error_msg=error_msg[0]), error_msg[1], headers, ) else: # No errors so we can set the confirmation confirmation.confirmed = True confirmation.save_to_db() logging.debug( f"Returning confirmation page for {confirmation.user.username}" ) return make_response( render_template("confirmation_success_page.html", username=confirmation.user.username, email=confirmation.user.email), 200, headers, )
def get(self, id): confirmation = ConfirmationModel.find_by_id(id) if not confirmation: response = jsonify({ "message": "This id does not belong to the database", "success": False, "code": 404 }) response.status_code = 404 return response if confirmation.expired: response = jsonify({ "message": "Confirmation link has been expired", "code": 400 }) response.status_code = 400 return response if confirmation.confirmed: response = jsonify({ "message": "Confirmation link for this user already confirmed", "code": 400 }) response.status_code = 400 return response # mark this confirmation record as confirmed and save confirmation.confirmed = True confirmation.save_to_db() headers = {"Content-Type": "text/html"} return make_response( render_template("confirmation_page.html", email=confirmation.user.email), 200, headers, )