コード例 #1
0
ファイル: app.py プロジェクト: Prosoffice/Company-site
def super_user():
    form = RegForm()
    if form.validate_on_submit():
        username = form.username.data
        full_name = form.full_name.data
        password = form.password.data
        role = form.role.data
        image = form.image.data

        # Process password
        password_hash = generate_password_hash(password)

        # Process image
        f = image
        image_id = str(uuid.uuid4())
        file_name = image_id + '.png'
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], file_name)
        Image.open(f).save(file_path)

        # Store staff to the database
        staff = models.Staff(username=username,
                             full_name=full_name,
                             password=password_hash,
                             role=role,
                             image=image_id)
        db.session.add(staff)
        db.session.commit()
        print(f"Staff {username} added")
        return redirect("/")
    return render_template('super.html', form=form)
コード例 #2
0
ファイル: admin.py プロジェクト: iilnar/hotel_management
def edit_staff(staff_passport):
    staff = get_db().get_staff(staff_passport)
    if request.method == 'POST':
        if staff_passport == request.form['passport']:
            new_staff = models.Staff(request.form)
            new_staff.hotel_id = g.user.hotel_id

            if staff is None:
                get_db().add_staff(staff)
            else:
                get_db().update_staff(staff)
            return redirect(url_for('staff', hotel_id=g.user.hotel_id))
    if not check_permission(staff=staff):
        return redirect(
            url_for('error',
                    error='Passport is already taken or do not cheat'))
    return render_template('staff_info.html', staff=staff, isNew=False)
コード例 #3
0
ファイル: db.py プロジェクト: iilnar/hotel_management
 def get_staff(self, id: int):
     return models.Staff(self.query("SELECT * from staff WHERE passport = %s" % id, one=True))
コード例 #4
0
ファイル: db.py プロジェクト: iilnar/hotel_management
 def get_all_staff(self, hotel_id):
     q = self.query("SELECT * FROM staff WHERE hid = %s" % hotel_id)
     if q is None:
         q = []
     return [models.Staff(x) for x in q]
コード例 #5
0
ファイル: admin.py プロジェクト: iilnar/hotel_management
def new_staff():
    return render_template('staff_info.html',
                           staff=models.Staff(''),
                           is_new=True)
コード例 #6
0
    def post(self):
        email = (self.request.get('email')).lower()
        password = self.request.get('password')
        auth = self.auth

        if not auth.get_user_by_session():
            accType = 'customer'
            customer = models.Customer()
        else:
            accType = self.request.get('accType')
            customer = models.Staff()

        customer.Email = email
        customer.First_Name = self.request.get('firstname')
        customer.Last_Name = self.request.get('lastname')
        customer.Contact_No = int(self.request.get('contact'))
        customer.Address = self.request.get('address')
        customer.postalCode = int(self.request.get('postalcode'))

        #unique_properties = ['email_address']
        acct_data = self.user_model.create_user(email,
                                                email_address=email,
                                                password_raw=password,
                                                first_name=customer.First_Name,
                                                accounType=accType,
                                                verified=False)

        if not mail.is_email_valid(email):
            self.display_message('invalid email entered')
            return

        if not acct_data[0]:  #acct_data is a tuple
            self.display_message('Unable to create user for email %s because \
            it already exist' % (email))
            return

        customer.put()
        user = acct_data[1]
        user_id = user.get_id()

        token = self.user_model.create_signup_token(user_id)

        verification_url = self.uri_for('verification',
                                        type='v',
                                        user_id=user_id,
                                        signup_token=token,
                                        _full=True)

        msg = 'Send an email to user in order to verify their address. \
          They will be able to do so by visiting <a href="{url}">{url}</a>'

        message = mail.EmailMessage()
        message.sender = '*****@*****.**'
        message.to = email
        message.body = """
        testing email
        %s
        """ % msg.format(url=verification_url)
        message.Send()

        #self.display_message(msg.format(url=verification_url))
        self.display_message(
            'A verification email has been sent to the respective email!')