def initialize_instance(): Admin.insert_admin(g.data['user'], g.data['password']) Domain(name='默认部员域').save() Role.new_role('成员', 0, []) Role.new_role('部长', 64, [ 'new_user', 'remove_user', 'rename_user', 'alloc_user', 'ls_user', 'import_from_sheet' ]) Role.new_role('总监', 4096, ['*']) with open('isinit.flag', 'w') as f: pass return trueReturn(msg="初始化完成")
def admin_signup(): cpf = request.form.get("cpf") name = request.form.get("name") email = request.form.get("email") password = generate_password_hash(request.form.get("password")) createdAt = str(date.today()) modifiedAt = str(date.today()) admin = Admin(cpf=cpf, name=name, email=email, password=password, createdAt=createdAt, modifiedAt=modifiedAt) if admin.create(): return redirect("/login/") return render_template("register-page.html")
def signin(): name = g.data.get("username", "").strip() password = g.data.get("password", "") user = Admin.objects(user_id=name).first() if not user or not user.valid_password(password): return falseReturn(None, "用户名或密码有误") return trueReturn({ 'user': user.get_base_info(), 'token': generate_jwt(user) })
def mverify_jwt(token): try: payload = jwt.decode(token, current_app.config['JWT_SECRET'], algorithm=['HS256']) if payload['iat'] < time.time(): return None, "登入超时" user = Admin.objects(id=payload['id']).first() if not user: return None, "无此用户" return user, "" except: return None, "数据错误"
def admin_login(): email = request.form.get("email") password = request.form.get("password") admin = Admin().getAdminByEmail(email) if admin: if check_password_hash(admin["password"], password): session["email"] = admin["email"] session["cpf"] = admin["cpf"] session["type"] = "admin" return redirect("/") error = "E-mail ou senha estão incorretos!" return render_template("login-page-admin.html", error=error)
def do_sign(): # shift改变排班的week只是记签到目的week,不作为判断是否允许签到的依据 wk = int( (datetime.datetime.now() - Admin.objects().first().server_starttime ).total_seconds()) % (86400 * 7) r = Routine.objects(user=g.user).first() ima = datetime.datetime.now().timestamp() + 28800 m = [] if r.signtime != r.shift: # 有调班: if int((ima + 259200) % 604800 / 86400) == int(r.shift / 5) and int( ima % 86400) in time_table[r.shift % 5]: if not Sign.objects(user=g.user, week=r.shift_week): if Sign.create(user=g.user, typ='s', week=r.shift_week): r = r.recover_shift() return trueReturn() else: r = r.recover_shift() m.append('【调班】本时间段内签过到') else: r = r.recover_shift() m.append('【调班】本周已签过到') else: m.append('【调班】不在签到时段内') # print(int((ima + 259200) % 604800 / 86400) == int(r.signtime / 5)) # print(ima % 86400 in time_table[r.signtime % 5]) # print(ima % 86400) # print(time_table[r.signtime % 5]) if int((ima + 259200) % 604800 / 86400) == int(r.signtime / 5) and int( ima % 86400) in time_table[r.signtime % 5]: if not Sign.objects(user=g.user, week=wk): if Sign.create(user=g.user, typ='n', week=wk): return trueReturn() else: m.append('【正常班次】本时间段内签过到') return falseReturn(msg='\n'.join(m)) else: m.append('【正常班次】本周已签过到') return falseReturn(msg='\n'.join(m)) else: m.append('【正常班次】不在签到时段内') return falseReturn(msg='\n'.join(m))
def set_starttime(): # 设置系统启动时间 d = datetime.datetime.strptime(g.data['time'], '%Y/%m/%d %H:%M:%S') Admin.objects().first().change_starttime(d) return trueReturn()