Ejemplo n.º 1
0
 def get_user(self):
     return (
         db_session.query(User)
         .filter_by(
             user=self.user.data.lower(), password=hashlib.md5(self.password.data.encode("utf-8")).hexdigest()
         )
         .first()
     )
Ejemplo n.º 2
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = db_session.query(User).filter_by(user=form.user.data.lower()).first()
        if user:
            flash("User exists.")
        else:
            user = User(form.user.data.lower(), form.key.data, form.email.data)
            db_session.add(user)

            # Set up the settings table when the first user is registered.
            if not Setting.query.filter_by(_id=1).first():
                settings = Setting(
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "off",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                )
                db_session.add(settings)
            # Commit all database changes once they have been completed
            db_session.commit()
            login_user(user)

    if current_user.is_authenticated:
        return redirect(url_for("home"))
    return render_template("register.html", form=form, title="Register")
Ejemplo n.º 3
0
def load_user(id):
    return db_session.query(User).filter_by(_id=id).first()
Ejemplo n.º 4
0
 def get_user(self):
     return db_session.query(User).filter_by(user=self.user.data.lower(), key=hashlib.md5(
         self.key.data.encode('utf-8')).hexdigest()).first()
Ejemplo n.º 5
0
def sign_in():
    sort = Cars.id
    #$return "Hello, {}!"#.format(auth.current_user())
    return render_template('index.html', sorts=sorts, cars=db_session.query(Cars).order_by(sort))#(desc(sort))
Ejemplo n.º 6
0
def old_car():
    message_sort = Message.text
    sort = Cars.id
    return render_template('index1.html', sorts=sorts, cars=db_session.query(Cars).order_by(sort),
                           messages=db_session.query(Message).order_by(message_sort))#(desc(sort))
Ejemplo n.º 7
0
def index():
    sort = Cars.price
    return render_template('index.html', sorts=sorts, cars=db_session.query(Cars).order_by(sort))#(desc(sort))
Ejemplo n.º 8
0
def delete_Message():
    try:
        num_rows_deleted = db_session.query(Message).delete()
        db_session.commit()
    except:
        db_session.rollback()
Ejemplo n.º 9
0
def load_user(id):
    return db_session.query(User).filter_by(_id=id).first()
Ejemplo n.º 10
0
 def get_user(self):
     return db_session.query(User).filter_by(
         user=self.user.data.lower(),
         password=hashlib.md5(
             self.password.data.encode('utf-8')).hexdigest()).first()
Ejemplo n.º 11
0
def check_reminder():
    """
    用途:
        检查哪些事件需要进行邮件提醒
    逻辑:
        这里逻辑简单说明下如下:
        01. 先获取到所有事件的到期时间
        02. 获取所有事件中每条事件都需要提前多少天进行提醒
        03. 计算从哪天开始进行提醒(过期时间 - 提前提醒天数 = 开始提醒的日期)
        04. 计算出来的·开始提醒日期· <= 现在时间 都进行报警
    :return:
    """
    # 邮箱配置信息
    config_info = redis_conn.hgetall(const.APP_SETTINGS)
    sm = SendMail(mail_host=config_info.get(const.EMAIL_HOST), mail_port=config_info.get(const.EMAIL_PORT),
                  mail_user=config_info.get(const.EMAIL_HOST_USER),
                  mail_password=config_info.get(const.EMAIL_HOST_PASSWORD),
                  mail_ssl=True if config_info.get(const.EMAIL_USE_SSL) == '1' else False)

    for msg in db_session.query(PaidMG).all():
        reminder_time = msg.paid_end_time - datetime.timedelta(days=int(msg.reminder_day))
        if reminder_time <= datetime.datetime.now():
            emails_list = redis_conn.hvals(msg.paid_name)
            print('msg_name---->',msg.paid_name)
            print('email_list---->',emails_list)
            content = """
                            <!DOCTYPE html>
                            <html lang="en">
                            <head>
                                <meta charset="UTF-8">
                                <title>OpenDevOps运维提醒邮件</title>
                                <style type="text/css">
                                    p {
                                        width: 100%;
                                        margin: 30px 0 30px 0;
                                        height: 30px;
                                        line-height: 30px;
                                        text-align: center;

                                    }

                                    table {
                                        width: 100%;
                                        text-align: center;
                                        border-collapse: collapse;
                                    }

                                    tr.desc {
                                        background-color: #E8E8E8;
                                        height: 30px;
                                    }

                                    tr.desc td {
                                        border-color: black;
                                    }

                                    td {
                                        height: 30px;
                                    }
                                </style>
                                <style>
                                    .bodydiv {
                                        width: 60%;
                                        margin: 0 auto;
                                    }

                                    .tc {
                                        text-align: center;
                                    }

                                    .content {
                                        margin: 10px 0 10px 30px;
                                    }
                                </style>
                            </head>
                            """
            content += """
                            <div class="bodydiv">
                                Hi, Ops:
                                <div class="content">
                                    你有以下事项提醒需要关注
                                </div>

                            <table>
                                <tr class="desc">
                                    <td>名称</td>
                                    <td>过期时间</td>
                                    <td>提前通知天数</td>
                                </tr>
                            """

            content += """
                                    <tr>
                                    <td>{}</td>
                                    <td>{}</td>
                                    <td>{}</td>
                                     </tr>""".format(msg.paid_name, msg.paid_end_time, msg.reminder_day)

            content += """
                                </table>
                                </div>
                                </body>
                                </html>

                        """
            # send_msg = msg.paid_name + "\n到期时间:" + str(msg.paid_end_time)
            #sm.send_mail("*****@*****.**", "运维信息提醒", send_msg)
            sm.send_mail(",".join(emails_list), '运维提醒信息', content, subtype='html')