def show(self, view: View, request: Request): token = request.param('token') # guest = OneTimeService.where('remember_token', token).get() # name = guest.pluck('customer_name')[0] # address = guest.pluck('address')[0] # email = guest.pluck('email')[0] # cell_phone = guest.pluck('cell_phone')[0] # service_id = guest.pluck('id')[0] if request.user(): user=request.user() firstname = user.firstname lastname = user.lastname address = user.address service_id = request.param('slug') token = user.remember_token return view.render('schedule', {"address": address, "firstname": firstname, "lastname": lastname, "service_id": service_id, 'token': token}) elif not request.user() and not token: # token = request.param('token') # return view.render('schedule', {'token': token}) return view.render('schedule') # return view.render('schedule', {'name':name, 'address':address, 'email': email, 'cell_phone':cell_phone, 'token': token}) elif not request.user(): token = request.param('token') guest = OneTimeService.where('remember_token', token).get() name = guest.pluck('customer_name')[0] address = guest.pluck('address')[0] email = guest.pluck('email')[0] cell_phone = guest.pluck('cell_phone')[0] return view.render('schedule', {'name':name, 'address':address, 'email': email, 'cell_phone':cell_phone, 'token': token}) else: return request.redirect('/login')
def reregister(self, request: Request, validate: Validator, auth: Auth): today_date = date.today() errors = request.validate( validate.required([ 'firstname', 'lastname', 'address', 'email', 'username', 'password', 'cell_phone' ]), validate.email('email'), validate.strong( 'password', length=8, special=1, uppercase=1, # breach=True checks if the password has been breached before. # Requires 'pip install pwnedapi' breach=False)) if errors: return request.back().with_errors(errors).with_input() if request.input('password') != request.input('password_confirm'): return request.back().with_errors({ 'error': ['Passwords do not match. Please make sure passwords match'] }) User.where( 'id', request.param('id')).update(firstname=request.input('firstname')) User.where( 'id', request.param('id')).update(lastname=request.input('lastname')) User.where( 'id', request.param('id')).update(address=request.input('address')) User.where( 'id', request.param('id')).update(cell_phone=request.input('cell_phone')) User.where('id', request.param('id')).update(email=request.input('email')) User.where( 'id', request.param('id')).update(username=request.input('username')) User.where('id', request.param('id')).update( password=password(request.input('password'))) User.where('id', request.param('id')).update(cancelled='No') User.where('id', request.param('id')).update(re_activated='Yes') User.where('id', request.param('id')).update(reactivated_on=today_date) auth.login(request.input('email'), request.input('password')) request.session.flash( 'success', 'Your account has been reactivated. Thank you for trusing us again.' ) return request.redirect('/')
def store(self, request: Request, response: Response, validate: Validator): errors = request.validate( validate.required("symptoms"), validate.required("diagnosis"), validate.required("treatment_plan"), validate.required("seen_by"), ) if errors: return errors patient_id = request.param("patient_id") patient_record = { "author": f"{self.user.gov_id}@afyamkononi", "timestamp": calendar.timegm(time.gmtime()), "symptoms": request.input("symptoms"), "diagnosis": request.input("diagnosis"), "treatment_plan": request.input("treatment_plan"), "seen_by": request.input("seen_by"), } patient_account = self.ibc.get_account_details( request.param("patient_id")) if patient_account.detail == "": return response.json({"error": "No such account"}) unpacked_data = json.loads(patient_account.detail) patient_history = utils.filter_medical_data(unpacked_data) history_update = [] if patient_history == []: history_update.append(patient_record) else: history_update += patient_history history_update.append(patient_record) history_update = utils.remove_duplicates(history_update) blockchain_status = self.ibc.set_patient_record( User.where("gov_id", patient_id).first(), history_update) print(blockchain_status) iroha_message = iroha_messages.update_medical_history_failed( blockchain_status) if iroha_message is not None: return response.json(iroha_message) return response.json({"success": "Medical data added successfully"})
def show(self, view: View, request: Request): project = Project.find(request.param('id')) return view.render('projects', { 'name': 'Joe', 'project': project, })
def update(self, request: Request): user = AUTH['model'].where('remember_token', request.param('token')).first() if user: user.password = bcrypt_password(request.input('password')) user.save() return request.redirect('/login')
def update(self, view: View, request: Request, validate: Validator, mail: Mail): schedule_date_info = request.input('date') customer = request.user() #checking that all required fields are entered and no errors are found. errors = request.validate( validate.required(['service_type', 'name', 'address'])) if errors: return request.back().with_errors(errors) if not schedule_date_info[0] or not schedule_date_info[1]: request.session.flash('success', "The service date and service time is required.") return request.back() update_schedule = Schedule.where('id', '=', request.param('slug')).update(service=request.input('service_type'), service_date=schedule_date_info[0], service_time=schedule_date_info[1]) #need to changed this variable to current new updated info to send in email confirmation. customer_schedule = Schedule.get().last() #sends email with pool appointment schedule details mail.subject('Pool Appointment Update Confirmation').to(customer.email).template('mail/appt_confirm', {'service_id': request.param('slug'), 'service': customer_schedule.service, 'service_date':customer_schedule.service_date, 'service_time':customer_schedule.service_time}).send() request.session.flash('success', 'Your appointment has been updated! A confirmation email has been sent.') return request.redirect('/')
def update(self, request: Request, validate: Validator): errors = request.validate( validate.required("password"), validate.confirmed("password"), validate.length( "password", min=config("auth.password_min_length"), max=config("auth.password_max_length"), ), ) if errors: request.session.flash("error", errors) return request.back() user = AUTH["model"].where("remember_token", request.param("token")).first() if user: user.password = bcrypt_password(request.input("password")) user.remember_token = None user.save() if request.user(): auth.sign_out() request.session.flash( "success", "Your password has been reset. Login below.") return request.redirect("/users/sign-in")
def confirm_email(self, request: Request, view: View, auth: Auth): """Confirm User email and show the correct response. Arguments: request {masonite.request.request} -- The Masonite request class. request {masonite.view.view} -- The Masonite view class. request {masonite.auth.auth} -- The Masonite Auth class. Returns: [type] -- [description] """ sign = Sign() token = sign.unsign(request.param('id')) if token is not None: tokenParts = token.split("::") if len(tokenParts) > 1: user = auth.auth_model.find(tokenParts[0]) if user.verified_at is None: timestamp = datetime.datetime.fromtimestamp(float(tokenParts[1])) now = datetime.datetime.now() timestamp_plus_10 = timestamp + datetime.timedelta(minutes=10) if now < timestamp_plus_10: user.verified_at = datetime.datetime.now() user.save() return view.render('auth/confirm', {'app': request.app().make('Application'), 'Auth': auth}) return view.render('auth/error', {'app': request.app().make('Application'), 'Auth': auth})
def __init__(self, league: League, view: View, request: Request): self.view = view self.request = request if request.param('id'): self.league = league.find(self.request.param('id')) else: self.league = None
def index(self, request: Request): article = Article.with_('comments.author').where( 'slug', request.param('slug')).first() comments = [] for comment in article.comments: comments.append(comment.payload()) return {'comments': comments}
def cancel(self, view: View, request: Request, auth: Auth): today_date = date.today() id = request.param('slug') cancelled_date = Schedule.where( 'id', request.param('slug')).get().pluck('cancelled_on') if cancelled_date[0] is not None: auth.logout() return view.render('pool_appointment_cancel', {'cancelled_date': cancelled_date}) else: Schedule.find(id).update(cancelled_on=today_date) auth.logout() return view.render('pool_appointment_cancel')
def delete(self, request: Request): comment = Comment.find(request.param('id')) if comment: comment.delete() return request.status(204) return {'error': 'Comment does not exist'}
def update(self, request: Request): user = AUTH["model"].where("remember_token", request.param("token")).first() if user: user.password = bcrypt_password(request.input("password")) user.save() return request.redirect("/login")
def update(self, request: Request, validate: Validator): errors = request.validate( validate.required("password"), # TODO: only available in masonite latest versions (which are not compatible with Masonite 2.2) validate.strong( "password", length=8, special=1, uppercase=1, # breach=True checks if the password has been breached before. # Requires 'pip install pwnedapi' breach=False, ), ) if errors: return request.back().with_errors(errors) user = ( AUTH["guards"]["web"]["model"] .where("remember_token", request.param("token")) .first() ) if user: user.password = bcrypt_password(request.input("password")) user.save() return request.redirect("/login")
def confirm_email(self, request: Request, view: View, auth: Auth, inertia: InertiaResponse): sign = Sign() token = sign.unsign(request.param("id")) if token is not None: tokenParts = token.split("::") if len(tokenParts) > 1: user = auth.auth_model.find(tokenParts[0]) if user.verified_at is None: timestamp = datetime.datetime.fromtimestamp( float(tokenParts[1])) now = datetime.datetime.now() timestamp_plus_10 = timestamp + datetime.timedelta( minutes=10) if now < timestamp_plus_10: user.verified_at = datetime.datetime.now() user.save() request.session.flash( 'success', 'Your email has successfully been verified.') return request.redirect("/") request.session.flash( 'error', 'Something went wrong. We could not verify your email address.') return request.redirect("/")
def reset(self, view: View, request: Request, auth: Auth): token = request.param("token") user = AUTH["guards"]["web"]["model"].where("remember_token", token).first() if user: return view.render( "auth/reset", {"token": token, "app": config("application"), "Auth": auth}, )
def data_get_thread(self, request: Request, view: View, auth: Auth): user_id = auth.user().id user = json.loads(User.find(user_id).to_json()) message_id = request.param('message_id') nylasController = NylasController() data = nylasController.getMessagesForThread(user['access_token'], message_id) return data
def create_display(self, request: Request): try: model = request.param('model') row = self.get_model_row_by_model_name(model) create_display = row['create_display'] return create_display except: return []
def role_permissions(self, request: Request, response: Response): role_id = request.param("role") blockchain_data = self.ibc.get_role_permissions(role_id) blockchain_data = protobuf_to_dict( blockchain_data.role_permissions_response) return response.json({"data": blockchain_data})
def data_get_message_clean(self, request: Request, view: View, auth: Auth): user_id = auth.user().id user = json.loads(User.find(user_id).to_json()) message_id = request.param('message_id') nylasController = NylasController() data = nylasController.getCleanMessage(user['access_token'], [message_id]) pprint(data) return data
def store(self, request: Request): post = Post.find(request.param('id')) post.title = request.input('title') post.body = request.input('body') post.save() return 'post updated'
def movie_wise_theaters(self, request: Request): movie_id = request.param('movie') # This orm with method does not support filtering that's why it's pulling all the record. # Other ways of filtering will be join, but since in other api's I have used orm, so to maintain the sanity # I am not using join here, but it totally possible theaters = Theater.with_('screens.shows').where_has( 'screens', lambda screen: screen.where_has( 'shows', lambda show: show.where('movie_id', movie_id))).get() return theaters
def store(self, view: View, request: Request): # сохранение обновленого содержимого поста в бд post = Post.find(request.param('id')) post.title = request.input('title') post.body = request.input('body') post.save() return 'post updated'
def delete(self, request: Request): """Logic to delete data from a given model """ record = self.model.find(request.param('id')) if record: record.delete() return record return {'error': 'Record does not exist'}
def reset(self, request: Request): token = request.param('token') user = AUTH['model'].where('remember_token', token).first() if user: return view( 'auth/reset', { 'token': token, 'app': request.app().make('Application'), 'Auth': Auth(request) })
def data_get_thread_clean(self, request: Request, view: View, auth: Auth): user_id = auth.user().id user = json.loads(User.find(user_id).to_json()) message_id = request.param('message_id') nylasController = NylasController() # data = nylasController.getCleanMessage(user['access_token'], [message_id]) //this was for the demo panel data = nylasController.getMessagesCleanedForThread(user['access_token'], message_id) return data
def reset(self, view: View, request: Request, auth: Auth): token = request.param('token') user = AUTH['guards']['web']['model'].where('remember_token', token).first() if user: return view.render('auth/reset', { 'token': token, 'app': config('application'), 'Auth': auth })
def callback(self, request: Request, socialite: Socialite, auth: Auth): user_info = socialite.driver(request.param('provider')).user() user = User.first_or_create( email=user_info.email, name=user_info.username, access_token=json.dumps(user_info.access_token) if isinstance( user_info.access_token, dict) else user_info.access_token, provider=user_info.provider) auth.once().login_by_id(user.id) return request.redirect('/')
def update(self, request: Request): """ /@id -> updated_todo """ todo = Todo.find(request.param("id")) todo.title = self.request.input("title") todo.completed = self.request.input("completed") todo.order = self.request.input("order") todo.save() return todo
def show(self, request: Request, response: Response): account_id = request.param("account_id") blockchain_data = self.ibc.get_all_account_transactions(account_id) blockchain_data = protobuf_to_dict(blockchain_data) blockchain_data = utils.format_transaction_data(blockchain_data) if blockchain_data is False: return response.json({"error": "No such permissions"}) return response.json({"data": blockchain_data})