Example #1
0
def doregister(name, nickname, password, mail):
    dao = UserDao()
    number = cc(nickname)
    ctext = generate_password_hash(password, method='pbkdf2:sha256:'+str(number['x']), salt_length=number['y'])
    cpassword = ctext.split('$')[-1]+"$"+ctext.split('$')[-2]
    user = User(name = name, nickname = nickname, password = cpassword, mail = mail)
    token = "http://127.0.0.1:8000/token/"+ctoken(nickname)
    verifymail(user.mail, token)
    return dao.register(user)
Example #2
0
def oauth_success():
    auth_code = request.args.get('code')
    credentials = flow.step2_exchange(auth_code)
    unique_id = credentials.id_token['sub']
    curr_user = UserDao.does_user_exist(unique_id)
    if not curr_user:
       curr_user = UserDao.add_user(unique_id,"",_generate_key(),credentials.access_token)
    session['logged_in_user'] = curr_user.id
    return redirect("/")
Example #3
0
def validatetoken(token):
    if token == ctoken(session['nickname']):
        dao = UserDao()
        user = User(cod = session['cod'])
        user.doverify()
        dao.doverify(user)
        session['verify'] = True
        return True
    else:
        return False
Example #4
0
def login():
    if request.method == "POST":
        userDao = UserDao()
        userName = request.form['userName']
        userPwd = request.form['userPwd']
        user = userDao.getUserByUserName(userName)
        if user and user.get('userpwd') == userPwd:
            # 请求转发
            return render_template('dashboard.html', name=userName)
        else:
            return "登录失败"
        pass
    else:
        return render_template('login.html', msg='登录失败')
    pass
Example #5
0
def checkUserName(request):
    dictObj = json.loads(request.body.decode('utf-8'))  # {'userName': '******'}
    userName = dictObj['userName']
    userDao = UserDao()
    result = userDao.findUserByUserName([userName])
    userDao.close()
    rDict = {}
    if result:
        rDict['result'] = 1
        pass
    else:
        rDict['result'] = 0
    # {'result':1}
    return HttpResponse(json.dumps(rDict), content_type='application/json')
    pass
Example #6
0
def verifyregister(nickname, password, mail):
    dao = UserDao()
    error = []
    user = User(nickname = nickname, mail = mail)
    result = dao.verifyuser(user)
    if result:
        for e in result:
            error.append(e)
    if len(nickname) < 6 or len(nickname) > 16:
        error.append(2)
    if len(password) < 6 or len(nickname) > 16:
        error.append(3)
    if len(error) == 0:
        return False
    else:
        return error
Example #7
0
def index():
    if 'logged_in_user' not in session:
        return redirect("/login")

    curr_user = UserDao.does_user_exist(session['logged_in_user'])
    res = {'api_key': curr_user.api_key}
    return render_template('index.html', res=res)
Example #8
0
def userLogin(request):
    userName = request.POST.get('userName', '')
    userPwd = request.POST.get('userPwd', '')

    userDao = UserDao()
    result = userDao.loginParams([userName, userPwd])

    if result:
        user = {}
        user['userName'] = userName
        request.session['user'] = user
        return render(request, 'main1.html')
        pass
    else:
        return render(request, 'index.html')
        pass
    pass
Example #9
0
def verifylogin(nickname, password):
    dao = UserDao()
    user = User(nickname = nickname)
    result = dao.login(user)
    if result:
        numbers = cc(result.nickname)
        pw = result.password.split('$')
        if check_password_hash("pbkdf2:sha256:"+str(numbers['x'])+"$"+pw[1]+"$"+pw[0], password):
            session['login'] = True
            session['name'] = result.name
            session['nickname'] = result.nickname
            session['cod'] = result.cod
            session['mail'] = result.mail
            session['verify'] = result.verify
            session['admin'] = result.admin
            return True
        else:
            return False
    else:
        return False
Example #10
0
def login(request):

    userName = request.POST.get('userName', '')
    userPwd = request.POST.get('userPwd', '')
    rememberMe = request.POST.get('rememberMe', '')

    userPwd = hashlib.md5(userPwd.encode(encoding='utf-8')).hexdigest()
    userDao = UserDao()

    result = userDao.loginParams([userName, userPwd])
    if result:
        user = {}
        user['userName'] = userName
        user['userId']   = result[0]['userid']
        user['userPic']  = result[0]['userpic']
        request.session['user'] = user
        return render(request, 'admin/index.html')
        pass
    else:
        return redirect('/login/')
        pass

    pass
Example #11
0
def regNewUser(request):
    # 普通的表单项
    userName = request.POST.get('userName', '')
    userPwd = request.POST.get('userPwd', '')
    userPhone = request.POST.get('userPhone', '')
    userIntro = request.POST.get('userIntro', '')
    userPicPath = ""  # 保存路径

    # 文件上传
    if request.POST:
        fileObj = request.FILES.get('userPic', None)
        # 将文件保存到本地
        if fileObj:
            userPicPath = '/static/upload/' + fileObj.name
            filePath = os.path.join(os.getcwd(), 'static/upload/' + fileObj.name)
            with open(filePath, 'wb+') as fp:
                for chunk in fileObj.chunks():
                    fp.write(chunk)
                    pass
                pass
    # 对用户的密码加密存储
    userPwd = hashlib.md5(userPwd.encode(encoding='utf-8')).hexdigest()

    userDao = UserDao()
    # 将用户的个人信息写入数据库
    result = userDao.createUser([userName, userPwd, userPhone, userPicPath, userIntro])
    userDao.commit()
    userDao.close()
    # 如果写入成功,跳转到登录页
    if result > 0:
        return render(request, 'login.html', {'success': 1})
        pass
    else:
        return render(request, 'newuser.html', {'success': 0})
        pass
    pass
Example #12
0
def user():
    userDao = UserDao()
    paramDict = {}
    if request.method == "POST":
        opr = request.form.get('opr')
        if opr == "add":
            userName = request.form.get('userName')
            phoneno = request.form.get('phoneno')
            email = request.form.get('email')
            params = [userName, '123456', '', 0, phoneno, email]
            result = userDao.createUser(params)
            userDao.commit()
        elif opr == "update":
            id = request.form.get('id')
            phoneno = request.form.get('phoneno')
            email = request.form.get('email')
            params = [phoneno, email]
            result = userDao.updateUser(params, id)
            userDao.commit()
            pass
        elif opr == "search":
            searhName = request.form.get('searchName')
            pageSize = request.form.get('pageSize')
            currentPage = request.form.get('currentPage')
            paramDict['searchName'] = searhName
            paramDict['pageSize'] = int(pageSize)
            paramDict['currentPage'] = int(currentPage)
            pass
    else:
        opr = request.args.get("opr")
        if opr == "disable":
            id = request.args.get('id')
            userDao.disableUserByUserId(id)
            userDao.commit()
            pass
        pass
    if paramDict.get('pageSize') == None or paramDict.get(
            'currentPage') == None:
        paramDict['pageSize'] = 10
        paramDict['currentPage'] = 1
        pass

    if not paramDict.get('searchName'):
        paramDict['searchName'] = ""
        pass
    userList = userDao.getUserListPage(paramDict)
    counts = userDao.getUserCounts(paramDict).get("counts")
    # 计算总共有多少页
    totalPage = int(
        counts // paramDict.get('pageSize')) if counts % paramDict.get(
            'pageSize') == 0 else int(counts // paramDict.get('pageSize')) + 1

    paramDict['totalPage'] = totalPage
    paramDict['counts'] = counts
    return render_template('sys/user.html',
                           userList=userList,
                           paramDict=paramDict)
Example #13
0
def getUserList(request):
    # 获取查询条件
    userName = request.POST.get('userName', '')
    userPhone = request.POST.get('userPhone', '')
    userState = request.POST.get('userState', '')
    userId = request.POST.get('userId', '')
    opr = request.POST.get('opr', '')
    pageSize = request.POST.get('pageSize', 0)
    currentPage = request.POST.get('currentPage', 0)

    if pageSize == 0 or pageSize == "":
        pageSize = 10
        pass
    if currentPage == 0 or currentPage == "":
        currentPage = 1
        pass

    userDao = UserDao()

    params = {'userName': userName,
              'userPhone': userPhone,
              'userState': userState,
              'pageSize': int(pageSize),
              'currentPage': int(currentPage) }

    if opr == 'delUser':

        result = userDao.removeUser([userId])
        params['result'] = result
        pass

    # 查询用户的个人信息
    if opr == 'update':
        uUser = userDao.findUserByUserId([userId])
        return render(request, 'admin/sysmgr/updateuser.html', {'params': params, 'uUser': uUser})
        pass

    # 提交修改用户的个人信息
    if opr == 'submitUpdate':
        userIntro = request.POST.get('userIntro', '')
        userPicPath = ""
        # 文件上传
        if request.POST:
            fileObj = request.FILES.get('userPic', None)
            # 将文件保存到本地
            if fileObj:
                userPicPath = '/static/upload/' + fileObj.name
                filePath = os.path.join(os.getcwd(), 'static/upload/' + fileObj.name)
                with open(filePath, 'wb+') as fp:
                    for chunk in fileObj.chunks():
                        fp.write(chunk)
                        pass
                    pass
                pass
            pass
        result = userDao.updateUser([userPhone, userPicPath, userIntro, userId])
        pass

    counts = userDao.findUserCounts(params)
    totalPage = counts // int(pageSize) if counts % int(pageSize) == 0 else counts // int(pageSize) + 1
    params['counts'] = counts
    params['totalPage'] = totalPage
    # 计算两个值:startRow
    startRow = (int(currentPage) - 1) * int(pageSize)
    params['startRow'] = startRow
    userList = userDao.findPageUserList(params)
    userDao.close()
    return render(request, 'admin/sysmgr/userinfo.html', {'userList': userList, 'params': params})
    pass
from dao.userdao import UserDao
from dao.projectdao import ProjectDao
from dao.ruledao import RuleDao
from dao.analysisitemdao import AnalysisItemDao

user_dao = UserDao()
project_dao = ProjectDao()
rule_dao = RuleDao()
analysis_item_dao = AnalysisItemDao()
Example #15
0
from controller.getpic import Download
from controller.getpic1 import Img
from utils.pageutils import Pagination
import importlib, sys
importlib.reload(sys)
from dao.demo_util import DBUtils
from entity.user import User
from dao.userdao import UserDao
import os
from datetime import timedelta
from star import spiderThread
from star1 import spiderThread1
app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(24)
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=30)
userDao = UserDao()
db = DBUtils()
citys = []


#主页
@app.route('/')
def index():
    print(session.get("userName"))
    return render_template('index.html')


#登录页面
@app.route('/log')
def log():
    return render_template('login.html')
Example #16
0
def _valid_api_key(request):
    if 'Authorization' in request.headers:
        api_key = request.headers['Authorization']
        if UserDao.valid_api_key(api_key):
            return True
    return False