Example #1
0
    def post(self):
        # 获取表单数据
        args = parser.parse_args()

        username = args.get('username')
        password = args.get('password')
        email = args.get('email')
        # re 邮箱验证
        mailre = "[a-z0-9_]+@[a-z0-9]+\.[a-z]{2,4}"
        if len(re.findall(mailre, email, re.I)) != 0:
            print(username, password, email)

            u_token = uuid.uuid4()
            print(u_token)
            # password = genetrate_password(password)
            # print(password)

            # 插入
            user = User(username=username, email=email, u_token=u_token)

            user.generate_password(password)

            try:
                db.session.add(user)
                db.session.commit()

                # 发送激活邮
                # 设置缓存,用来保存用户信息{字典}
                cache.set(str(u_token), username, timeout=60 * 2)
                '''
                subject, recipients, emailTmp, **kwargs
                '''

                send_mail_util.delay(
                    subject='账号激活',
                    recipients=[email],
                    emailTmp='activationUserEmail',
                    username=username,
                    url='http://127.0.0.1:5000/activation?u_token=' +
                    str(u_token))

                # async_send_mail_util(subject='账号激活',
                #                      recipients=[email],
                #                      emailTmp='activationUserEmail',
                #                      username=username,
                #                      url='http://127.0.0.1:5000/activation?u_token=' + str(u_token))

            except Exception as e:
                # 回滚
                # print(e)
                logs().error(e)
                db.session.rollback()
                return {"msg": "用户已存在", 'status': 422}
        else:
            return {"msg": "邮箱格式错误", 'status': 422}

        return {"msg": "用户注册成功", 'status': 201}
def sql_connect(login):
    # this connects to the database and further queries can be made inside the sql database
    # login[0] = host_address
    # login[1] = mysql_user_name
    # login[2] = mysql_password
    # login[3] = database_name
    try:
        db = mysql.connect(login[0], login[1], login[2], login[3])
    except mysql.OperationalError:
        # here use more greedy technique for connecting to mysql server in-case the previous step fails
        log.logs('Invalid Credentials for database')
        popup.popup_widget('Fatal Error Occurred\nContact Admin to resolve the issue')
        exit(0)
    return db
def validate_database(login):        # method for validating whether the database is configured properly
    # define a cursor to the database
    valid_database_flag = False
    db = sql_connect(login)
    cursor = db.cursor()
    # sql query
    try:
        rows = str(cursor.execute(show_tables))
    except mysql.ProgrammingError:     # need to specify the particular exception
        log.logs('Invalid Command')

    if rows != '0':
        valid_database_flag = True
    else:
        valid_database_flag = False
        log.logs('Database Empty')
    return db, cursor, valid_database_flag
Example #4
0
    def __init__(self):
        # 连接mongodb
        self._client = pymongo.MongoClient(MONGO_URL)
        self._db = self._client[MONGO_DB]

        # 初始化日志记录
        self._logger=log.logs()

        # 请求连接
        self._base_url = 'http://www.6vhao.tv/'
        self._base_header = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6726.400 QQBrowser/10.2.2265.400'
        }
Example #5
0
 def __init__(self, save_path):
     """
     针对指定数据进行完整备份
     :param save_path:压缩后的保存位置
     file:{path:'path_to_file_or_dir'}
     data:{
         type:'mysql_or_sqlserver',
         address:'link_to_database',
         port:port,
         database:database_name,
         user:database_user,
         password:database+password
     }
     """
     self.save_path = save_path
     self.tarfileTool = TarTool()
     self.logTool = logs()
Example #6
0
from flask.logging import default_handler
from flask import abort, redirect, url_for
from flask import render_template
from flask import make_response
from urllib import parse
import short_url_fun
import token_calculation as token
import conf
import time
import json
import db
import log

config = conf.GetConfig()
app = Flask(__name__)
logwrite = log.logs()


@app.route('/urlquery', methods=['GET'])
def urlquery():
    if request.method == "GET":
        request_host_url = request.host_url
        log_content = ("action:%s Host:%s Client_ip:%s User-Agent:%s " %
                       (request.path, request.headers.get('Host'),
                        request.headers.get('X-Forwarded-For'),
                        request.headers.get('User-Agent')))

        result = {}

        if not 'shorturl' in request.args.keys():
            #判断参数是否全部传递
Example #7
0
import os, pymysql
from log import logs

logTool = logs()


class mysql:
    def __init__(self, address, port, database, username, password, save_path):
        self.save_path = save_path
        self.address = address
        self.port = port
        self.database = database
        self.username = username
        self.password = password

    def _GetDatabaseNames(self):
        conn = pymysql.connect(self.address, self.username, self.password, use_unicode=True, charset="utf8")
        cur = conn.cursor()
        cur.execute('show databases;')
        dbs = cur.fetchall()
        data_list = [tuple[0] for tuple in dbs]
        cur.close()
        conn.close()
        return data_list

    def backUp(self):
        dbs = self._GetDatabaseNames()
        if self.database=='':
            try:
                # mysqldump -uroot -p123456 -A > /data/mysqlDump/mydb.sql
                cmd = "mysqldump -h%s -P %s -u%s -p%s --all-databases | gzip > %s" % (
Example #8
0
 def __init__(self, buf_size=1024 * 8):
     self.bufSize = buf_size
     self.fin = None
     self.fout = None
     self.logTool = logs()
Example #9
0
import smtplib, time, requests, os, hashlib, json
import log, traceback
from Tools import Config
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from datetime import datetime
import configparser
import lead
from requests.adapters import HTTPAdapter

cf = configparser.ConfigParser()
cf.read("/program/cache.ini", encoding="utf-8")  # 读取配置文件,如果写文件的绝对路径,就可以不用os模块

logTool = log.logs()
conf = Config()


class Mail:
    def __init__(self):
        mail_conf = conf.get('save')['mail']
        self.host = mail_conf['host']
        self.port = mail_conf['port']
        self.to = mail_conf['to']
        self.user = mail_conf['user']
        self.password = mail_conf['password']

    def save(self, path, name):

        dt = datetime.now()
        logTool.info('开始构建邮件')