Ejemplo n.º 1
0
 def dispatch_request(self):
     if chckuserpermisson() is False:
         return reponse(code=MessageEnum.permiss_is_ness.value[0],
                        message=MessageEnum.permiss_is_ness.value[1],
                        data='')
     userjobnum = request.get_json()
     try:
         id = int(userjobnum['id'])
         job_num = int(userjobnum['jobnum'])
     except Exception as e:
         logger.exception(e)
         return reponse(code=MessageEnum.activ_is_int.value[0],
                        message=MessageEnum.activ_is_int.value[1])
     user = User.query.filter_by(id=id, status=False).first()
     if not user:
         return reponse(
             code=MessageEnum.login_user_not_exict_message.value[0],
             message=MessageEnum.login_user_not_exict_message.value[1])
     try:
         user_job = User.query.filter_by(jobnum=job_num).first()
         if user_job:
             return reponse(code=MessageEnum.activi_user_jobnum.value[0],
                            message=MessageEnum.activi_user_jobnum.value[1])
     except Exception as e:
         logger.exception(e)
         pass
     if (user.jobnum is None or user.jobnum == "None"):
         user.jobnum = job_num
         db.session.add(user)
         db.session.commit()
         return reponse(code=MessageEnum.successs.value[0],
                        message=MessageEnum.successs.value[1],
                        data='')
     return reponse(code=MessageEnum.activi_user_jobnum_is.value[0],
                    message=MessageEnum.activi_user_jobnum_is.value[1])
Ejemplo n.º 2
0
 def dispatch_request(self, id):
     if chckuserpermisson() is False:
         flash(MessageEnum.permiss_is_ness.value[1])
         return redirect(request.headers.get('Referer'))
     user = User.query.filter_by(username=session.get('username')).first()
     new_ad = User.query.filter_by(id=id).first()
     if new_ad != user:
         if user.is_sper == 1:
             new_ad.set_password('111111')
             try:
                 db.session.commit()
                 msg = Message(u"密码修改通知",
                               sender=user.email,
                               recipients=user.email)
                 msg.body = u"密码修改成功, 你的用户名:%s,你的密码是:%s" % (user.username,
                                                            "111111")
                 msg.html = '<a href="http://127.0.0.1:5000/login">去登录</a>'
                 mail = Mail()
                 mail.send(msg)
                 flash(MessageEnum.reset_success_message.value[1])
                 return redirect(url_for('home.adminuser'))
             except Exception as e:
                 logger.exception(e)
                 db.session.rollback()
                 flash(MessageEnum.user_reset_error.value[1])
                 return redirect(url_for('home.adminuser'))
         flash(MessageEnum.user_reset_isnot_amin.value[1])
         return redirect(url_for('home.adminuser'))
     flash(MessageEnum.user_reset_owner.value[1])
     return redirect(url_for('home.adminuser'))
Ejemplo n.º 3
0
 def dispatch_request(self,id):
     if chckuserpermisson() == False:
         flash('权限不足,不能解冻用户')
         return  redirect(request.headers.get('Referer'))
     user=User.query.filter_by(username=session.get('username')).first()
     new_ad=User.query.filter_by(id=id).first()
     if new_ad.status==False:
         flash(u'用户没有处于冻结状态')
         return redirect(url_for('home.adminuser'))
     if new_ad!=user:
         if new_ad.is_sper==1:
             new_ad.status =False
             try:
                 db.session.commit()
                 flash(u'解冻成功')
                 return redirect(url_for('home.adminuser'))
             except Exception as e:
                 db.session.rollback()
                 flash(u'解冻失败,原因是:%s'%e)
                 return  redirect(url_for('home.adminuser'))
         flash(u'自己不能解冻自己')
         return redirect(url_for('home.adminuser'))
     new_ad.status=False
     db.session.commit()
     flash(u'解冻成功!')
     return redirect(url_for('home.adminuser'))
Ejemplo n.º 4
0
 def dispatch_request(self, id):
     if chckuserpermisson() is False:
         flash(MessageEnum.permiss_is_ness.value[1])
         return redirect(request.headers.get('Referer'))
     user = User.query.filter_by(username=session.get('username')).first()
     if user.is_sper != 1:
         flash(MessageEnum.permiss_is_ness.value[1])
         return redirect(request.headers.get('Referer'))
     new_ad = User.query.filter_by(id=id).first()
     if new_ad.status is True:
         flash(MessageEnum.free_is_again.value[1])
         return redirect(url_for('home.adminuser'))
     if new_ad == user:
         flash(MessageEnum.ower_cannot_free_me.value[1])
         return redirect(url_for('home.adminuser'))
     new_ad.status = True
     try:
         db.session.commit()
         flash(MessageEnum.free_is_success.value[1])
         return redirect(url_for('home.adminuser'))
     except Exception as e:
         logger.exception(e)
         db.session.rollback()
         flash(MessageEnum.free_user_error.value[1])
         return redirect(url_for('home.adminuser'))
Ejemplo n.º 5
0
 def get(self):
     if chckuserpermisson() == False:
         flash('权限不足,不能为项目添加用户')
         return  redirect(request.headers.get('Referer'))
     wrok=Work.query.all()
     projects=Project.query.filter_by(status=False).all()
     return render_template('add/add_user.html', wroks=wrok, projects=projects)
Ejemplo n.º 6
0
 def dispatch_request(self):
     if chckuserpermisson() == False:
         return jsonify({'code': 13, 'msg': permiss_is_ness, 'data': ''})
     userjobnum = request.get_json()
     try:
         id = int(userjobnum['id'])
         job_num = int(userjobnum['jobnum'])
     except Exception as e:
         return jsonify({'code': 13, 'msg': activ_is_int})
     user = User.query.filter_by(id=id, status=False).first()
     if not user:
         return jsonify({'code': 13, 'msg': login_user_not_exict_message})
     try:
         user_job = User.query.filter_by(jobnum=job_num).first()
         if user_job:
             return jsonify({'code': 13, 'msg': activi_user_jobnum})
     except Exception as e:
         pass
     if (user.jobnum == None or user.jobnum == "None"):
         user.jobnum = job_num
         db.session.add(user)
         db.session.commit()
         return jsonify({'code': 20, 'msg': '激活成功', 'data': ''})
     return jsonify({
         'code': 13,
         'msg': '激活失败',
         'data': activi_user_jobnum_is
     })
Ejemplo n.º 7
0
 def dispatch_request(self, id):
     if chckuserpermisson() is False:
         flash(MessageEnum.permiss_is_ness.value[1])
         return redirect(request.headers.get('Referer'))
     new_ad = User.query.filter_by(id=id, status=False).first()
     if not new_ad:
         flash(MessageEnum.login_user_not_exict_message.value[1])
         return redirect(url_for('home.adminuser'))
     if new_ad == user:
         flash(MessageEnum.admin_cannot_use.value[1])
         return redirect(url_for('home.adminuser'))
     return redirect(url_for('home.adminuser'))
Ejemplo n.º 8
0
 def dispatch_request(self,id):
     if chckuserpermisson() is False:
         flash('权限不足,不能取消管理员')
         return  redirect(request.headers.get('Referer'))
     new_ad=User.query.filter_by(id=id,status=False).first()
     if not new_ad:
         flash(u'找不到你要设置的管理员的用户')
         return redirect(url_for('home.adminuser'))
     if new_ad==user:
         flash(u'自己不能取消自己的管理员')
         return redirect(url_for('home.adminuser'))
     return redirect(url_for('home.adminuser'))
Ejemplo n.º 9
0
 def dispatch_request(self, id):
     if chckuserpermisson() == False:
         flash('权限不足,不能删除测试报告')
         return redirect(request.headers.get('Referer'))
     delTest = TestResult.query.filter_by(id=id, status=False).first()
     if not delTest:
         flash('要删除的测试报告不存在')
         return redirect(url_for('home.test_rep'))
     delTest.status = True
     try:
         db.session.commit()
         flash(u'删除成功')
         return redirect(url_for('home.test_rep'))
     except Exception as e:
         db.session.rollback()
         flash('删除测试报告失败,原因:%s' % e)
         return redirect(url_for('home.test_rep'))
Ejemplo n.º 10
0
 def dispatch_request(self):
     if chckuserpermisson() == False:
         return jsonify({'code': 13, 'msg': permiss_is_ness, 'data': ''})
     projec = request.get_json()
     try:
         username = projec['username']
         por = projec['url']
         if por == '':
             return jsonify({'code': 14, 'msg': '请选择项目', 'data': ''})
         pan_user = User.query.filter_by(username=username).first()
         if not pan_user:
             return jsonify({
                 'code': 15,
                 'msg': login_user_not_exict_message,
                 'data': ''
             })
         if pan_user.is_sper is True:
             return jsonify({'code': 16, 'msg': '超级管理员不用设置项目', 'data': ''})
         pand_por = Project.query.filter_by(project_name=por).first()
         if not pand_por:
             return jsonify({'code': 17, 'msg': '设置的项目不存在', 'data': ''})
         pro_per = Quanxian.query.filter_by(project=pand_por.id).all()
         oneadmin = []
         for i in pro_per:
             if i.rose == 2:
                 oneadmin.append(i.user.all())
         if [pan_user] in oneadmin:
             return jsonify({'code': 18, 'msg': '你已经是项目管理员了,不需要再次设置'})
         if (len(oneadmin)) > OneAdminCount:
             return jsonify({'code': 19, 'msg': '单个项目的管理员已经达到后台设置的个数限制'})
         for roses in pan_user.quanxians:
             if roses.project == pand_por.id:
                 roses.rose = 2
         try:
             db.session.commit()
             return jsonify({'code': 200, 'msg': '设置管理成功'})
         except:
             db.session.rollback()
             return jsonify({'code': 20, 'msg': '设置管理失败', 'data': ''})
     except Exception as e:
         return jsonify({
             'code': 21,
             'msg': '设置过程目前存在异常,原因是:%s' % e,
             'data': ''
         })
Ejemplo n.º 11
0
 def dispatch_request(self, id):
     if chckuserpermisson() is False:
         flash('权限不足,不能重置密码')
         return redirect(request.headers.get('Referer'))
     user = User.query.filter_by(username=session.get('username')).first()
     new_ad = User.query.filter_by(id=id).first()
     if new_ad != user:
         if user.is_sper == 1:
             new_ad.set_password('111111')
             try:
                 db.session.commit()
                 flash(u'已经重置!密码:111111')
                 return redirect(url_for('home.adminuser'))
             except Exception as e:
                 db.session.rollback()
                 flash('重置密码失败,原因:%s' % e)
                 return redirect(url_for('home.adminuser'))
         flash(u'不是管理员不能重置')
         return redirect(url_for('home.adminuser'))
     return redirect(url_for('home.adminuser'))
Ejemplo n.º 12
0
 def dispatch_request(self, id):
     if chckuserpermisson() is False:
         flash(permiss_is_ness)
         return redirect(request.headers.get('Referer'))
     user = User.query.filter_by(username=session.get('username')).first()
     new_ad = User.query.filter_by(id=id).first()
     if new_ad != user:
         if user.is_sper == 1:
             new_ad.set_password('111111')
             try:
                 db.session.commit()
                 flash(reset_success_message)
                 return redirect(url_for('home.adminuser'))
             except Exception as e:
                 db.session.rollback()
                 flash(user_reset_error)
                 return redirect(url_for('home.adminuser'))
         flash(user_reset_isnot_amin)
         return redirect(url_for('home.adminuser'))
     flash(user_reset_owner)
     return redirect(url_for('home.adminuser'))
Ejemplo n.º 13
0
 def dispatch_request(self, id):
     if chckuserpermisson() == False:
         flash(permiss_is_ness)
         return redirect(request.headers.get('Referer'))
     user = User.query.filter_by(username=session.get('username')).first()
     new_ad = User.query.filter_by(id=id).first()
     if new_ad.status == False:
         flash(user_is_not_free)
         return redirect(url_for('home.adminuser'))
     if new_ad != user:
         new_ad.status = False
         try:
             db.session.commit()
             flash(user_is_un_free)
             return redirect(url_for('home.adminuser'))
         except Exception as e:
             db.session.rollback()
             flash(user_is_unfree_success)
             return redirect(url_for('home.adminuser'))
     flash(ower_not_free_me)
     return redirect(url_for('home.adminuser'))
Ejemplo n.º 14
0
 def dispatch_request(self,id):
     if chckuserpermisson() == False:
         flash('权限不足,不能冻结')
         return  redirect(request.headers.get('Referer'))
     user=User.query.filter_by(username=session.get('username')).first()
     if user.is_sper!=1:
         flash('权限不足,不能冻结')
         return redirect(request.headers.get('Referer'))
     new_ad=User.query.filter_by(id=id).first()
     if new_ad.status==True:
         flash(u'已经冻结,无需再次冻结')
         return redirect( url_for('home.adminuser'))
     if new_ad==user:
         flash(u'自己不能冻结自己')
         return redirect( url_for('home.adminuser'))
     new_ad.status=True
     try:
         db.session.commit()
         flash(u'已经冻结成功')
         return redirect( url_for('home.adminuser'))
     except Exception as  e:
         db.session.rollback()
         flash(u'冻结用户失败!原因:%s'%e)
         return redirect(url_for('home.adminuser'))
Ejemplo n.º 15
0
 def dispatch_request(self):
     if chckuserpermisson() is False:
         return reponse(code=MessageEnum.permiss_is_ness.value[0],
                        message=MessageEnum.permiss_is_ness.value[1],
                        data='')
     projec = request.get_json()
     try:
         username = projec['username']
         por = projec['url']
         if por == '':
             return reponse(code=MessageEnum.select_project_not.value[0],
                            message=MessageEnum.select_project_not.value[1],
                            data='')
         pan_user = User.query.filter_by(username=username).first()
         if not pan_user:
             return reponse(
                 code=MessageEnum.login_user_not_exict_message.value[0],
                 message=MessageEnum.login_user_not_exict_message.value[1],
                 data='')
         if pan_user.is_sper is True:
             return reponse(
                 code=MessageEnum.super_admin_not_set_project.value[0],
                 message=MessageEnum.super_admin_not_set_project.value[1],
                 data='')
         pand_por = Project.query.filter_by(project_name=por).first()
         if not pand_por:
             return reponse(
                 code=MessageEnum.set_project_bot_exict.value[0],
                 message=MessageEnum.set_project_bot_exict.value[1],
                 data='')
         pro_per = Quanxian.query.filter_by(project=pand_por.id).all()
         oneadmin = []
         for i in pro_per:
             if i.rose == 2:
                 oneadmin.append(i.user.all())
         if [pan_user] in oneadmin:
             return reponse(code=MessageEnum.set_is_admin.value[0],
                            message=MessageEnum.set_is_admin.value[1])
         if (len(oneadmin)) > OneAdminCount:
             return reponse(code=MessageEnum.project_admin_many.value[0],
                            message=MessageEnum.project_admin_many.value[1])
         for roses in pan_user.quanxians:
             if roses.project == pand_por.id:
                 roses.rose = 2
         try:
             db.session.commit()
             return reponse(code=MessageEnum.successs.value[0],
                            message=MessageEnum.successs.value[1])
         except Exception as e:
             logger.exception(e)
             db.session.rollback()
             return reponse(code=MessageEnum.set_fail.value[0],
                            message=MessageEnum.set_fail.value[1],
                            data='')
     except Exception as e:
         logger.exception(e)
         return reponse(
             code=MessageEnum.set_project_admin_exception.value[0],
             message=MessageEnum.set_project_admin_exception.value[1] +
             '原因是:%s' % e,
             data='')