Esempio n. 1
0
 def delete(self):
     mid = request.args.get('mid')
     movie = dao.getById(Movies, mid)
     if not movie:
         return {'msg': '你要删除的影片资源不存在'}
     dao.delete(movie)
     return {'msg': '删除 {} 影片成功'.format(movie.showname)}
Esempio n. 2
0
def sendMail(uId):
    try:
        import manage
    except:
        pass
    global manage
    with manage.app.test_request_context():
        user = dao.getById(User, uId)
        # 生成token
        token = md5_crypt(str(uuid.uuid4()))
        print('我得token', token)
        # 将token设置到redis缓存中
        mainApp.ext.cache.set(token, user.id, timeout=10 * 60)  # 允许10分钟来激活用户
        print('redis的token:', mainApp.ext.cache.get(token))
        # 激活的链接
        active_url = request.host_url + 'account/?opt=active&token=' + token
        # 发送邮件
        # 创建msg对象
        msg = Message(
            subject='淘票票激活用户',
            recipients=[user.email],  # 必须是列表,可添加多个元素
            sender='*****@*****.**')
        # 编辑内容
        msg.html = '<h1>{} 注册成功!</h1><br/><h3>请先<a href={}>激活</a>注册账号</h3><br/>' \
                   '<h3>可将下面地址复制到浏览器中进行激活</h3><p>{}</p>'. \
            format(user.nickname, active_url, active_url)

        # 发送邮件
        try:
            mainApp.ext.mail.send(msg)
            print('邮件已发送')
        except Exception as e:
            print(e)
            print('邮件发送失败')
Esempio n. 3
0
 def delete(self):
     cid = request.args.get('cid')
     cinemas = dao.getById(Cinemas, cid)
     if not cinemas:
         return {'msg': '您删除的影院不存在'}
     if not dao.delete(cinemas):
         return {'msg': '删除失败'}
     return {'msg': '删除成功'}
Esempio n. 4
0
 def wrapper(*args, **kwargs):
     token = request.args.get('token')
     if not token:
         token = request.form.get('token')
     user_id = session.get(token)
     loginUser = dao.getById(User, user_id)
     if not loginUser:
         return {'msg': '请先登录!'}
     if loginUser.rights & qx == qx:
         return fn(*args, **kwargs)
     qxObj = dao.queryOne(Qx).filter(Qx.right == qx).first()
     return {'msg': '您没有 {} 权限'.format(qxObj.name)}
Esempio n. 5
0
 def wrapper(*args,**kwargs):
     print('-check login-')
     token = request.args.get('token')
     user_id = session.get(token)
     loginUser = dao.getById(User,user_id)
     if not user_id:
         return {'msg':'用户必须先登录'}
     if loginUser.rights & qx == qx:
         return fun(*args,**kwargs)
     else:
         qxObj = dao.queryOne(Qx).filter(Qx.right==qx).first()
         return {'msg':'用户没有{}权限'.format(qxObj.name)}
Esempio n. 6
0
 def logout(self):
     logoutactiveParser=self.parser.copy()
     logoutactiveParser.add_argument('Token',required=True,help='token不能为空')
     args = logoutactiveParser.parse_args()
     logintoken = args.get('Token')
     print('退出的token',logintoken)
     user_id = session.get(logintoken)
     if not user_id:
         return {'status':701,'msg':'用户未登录,请先登录!'}
     user = dao.getById(User,user_id)
     if not user:
         return {'status':702,'msg':'用户退出失败,token无效!'}
     session.pop(logintoken)
     #session.clear()
     return {'status':200,'msg':'退出成功!'}
Esempio n. 7
0
    def addAlertMovie(self,qx):
        addmovieActive = self.parser.copy()
        addmovieActive.add_argument('id',type=int,required=True,help='电影编号不能为空')
        addmovieActive.add_argument('showname',required=True,help='电影名不能为空')
        addmovieActive.add_argument('shownameen',required=True,help='英文电影名不能为空')
        addmovieActive.add_argument('director',required=True,help='导演名不能为空')
        addmovieActive.add_argument('leadingRole',required=True,help='主演名不能为空')
        addmovieActive.add_argument('type',required=True,help='电影类型不能为空')
        addmovieActive.add_argument('country',required=True,help='所属国家不能为空')
        addmovieActive.add_argument('language',required=True,help='语言不能为空')
        addmovieActive.add_argument('duration',type=int,required=True,help='电影时间不能为空')
        addmovieActive.add_argument('screeningmodel',required=True,help='放映模式不能为空')
        addmovieActive.add_argument('openday',required=True,help='上映时间不能为空')
        addmovieActive.add_argument('backgroundpicture',required=True,help='背景图片不能为空')

        #验证请求参数
        args = addmovieActive.parse_args()
        movies_id = args.get('id')
        movies = dao.getById(Movies, movies_id)
        #判断用户是否执行修改权限
        if qx == QX.EDIT_QX:
            #print(movies.showname)
            #判断movies数据库中是否存在该电影,存在则判断为修改影片,否则为新增影片
            if not movies:
                return {'msg':'您所修改的电影不存在'}
        # 判断用户是否执行添加权限
        elif qx == QX.ADD_QX:
            if movies:
                return {'msg':'您所添加的电影已存在'}
            movies=Movies()
        #args是一个输入字段的字典
        for key,value in args.items():
            #判断key是否是movies的字段属性
            if hasattr(movies,key):
                print(key, ':', value)
                setattr(movies,key,value)
        # print('主演:',movies.leadingRole)
        # print('保存电影',dao.save(movies))
        if dao.save(movies):
            return {'msg':'{} 电影保存成功!'.format(movies.showname)}
        return {'msg':'电影保存失败,请检查必备属性是否输入'}
Esempio n. 8
0
    def get(self):
        # 从请求参数中获取opt和token参数值
        # 如果opt为avtive,则从redis缓存中查询token对应的user.id
        # 再通过 user.id 查询数据库中用户,最后更新用户的is_active状态
        # token = mainApp.ext.cache.get(str(request.args.get('token')))
        # 通过get请求获取opt数据

        args = self.parser.parse_args()
        opt = args.get('opt')
        # print('类型:', type(opt))
        # print(opt)
        # opt为请求状态
        if opt == 'active':
            activeParser = self.parser.copy()
            activeParser.add_argument('token', required=True, help='没有token')
            args = activeParser.parse_args()
            token = args.get('token')
            user_id = mainApp.ext.cache.get(token)
            if user_id:
                user = dao.getById(User, user_id)
                # print('用户',user)
                # print(type(user))
                user.is_active = True
                dao.save(user)
                return {'msg': '{} 激活成功'.format(user.nickname)}
            else:
                # 重新申请激活
                reactive_url = request.host_url + 'account/?opt=reactive'
                return {'msg': '激活超时,请重新激活'+reactive_url}
        elif opt == 'reactive':
            return self.reactive()

        elif opt == 'login':
            return self.login()

        elif opt == 'logout':
            return self.logout()
Esempio n. 9
0
    def post(self):
        #定义输入字段
        myImageactice = self.parser.copy()
        myImageactice.remove_argument('opt')    #移除opt的输入字段
        myImageactice.add_argument('img',type=FileStorage,location='files',
                                   required=True,help='必须要上传图片文件')
        myImageactice.add_argument('Token')
        args = myImageactice.parse_args()
        token = args.get('Token')
        if not token:
            return {'msg':'请登录!'}

        user_id = session.get(token)
        user = dao.getById(User,user_id)
        if not user:
            return {'msg':'Token无效,请确定您是否登录'}

        #获取image对象
        upImage:FileStorage = args.get('img')
        print('上传图片的文件名:',upImage.filename)
        #重新命名文件名
        newImage = str(uuid.uuid4()).replace('-','')+'.'+upImage.filename.split('.')[-1]
        print('新的文件名',newImage)
        upImage.save(os.path.join(settings.MEDIA_DIR,newImage))
        user.photo_1 = newImage
        dao.save(user)

        #定义输出字段
        out_image_fields={
            'msg':fields.String('文件上传成功!'),
            'data':fields.String,
            'access_token':fields.String
        }

        data={'data':newImage,
              'access_token':token}
        return marshal(data,out_image_fields)