def login(): resp = {'code':1,'msg':'成功','data':{}} data = request.values # print(data) code = data.get('code') if 'code' in data else '' nickname = data.get('nickName') if 'nickName' in data else '' avatar = data.get('avatarUrl') if 'avatarUrl' in data else '' gender = data.get('gender') if 'gender' in data else 1 # print(nickname) if not code or len(code) <1: resp['code'] = -1 resp['msg'] = 'code无效' return jsonify(resp) openid = MemberService.getOpenid(code) oauthmemberbind = OauthMemberBind.query.filter_by(openid=openid).first() if not oauthmemberbind: member = Member(nickname=nickname,gender=gender,avatar=avatar,salt=MemberService.getSalt()) db.session.add(member) db.session.commit() oauthmemberbind = OauthMemberBind(openid=openid,type=1,client_type='weixin',extra='',member_id=member.id) db.session.add(oauthmemberbind) db.session.commit() member = Member.query.get(oauthmemberbind.member_id) token = '%s#%s'%(MemberService.geneAuthCode(member),member.id) resp['data'] = {'token': token} return jsonify(resp)
def createTeam(): if session.get("id") is None: return redirect("/user/login") name = session.get("name") if request.method == "GET": return render_template('student_templates/createTeam.html', name=name) else: name = request.form.get("name") userId = session.get("id") course = CourseAndStudent.query.filter( CourseAndStudent.studentId == userId).first() with db.auto_commit(): team = Team() team.courseId = course.CourseId team.TeamName = name team.isFinish = 0 db.session.add(team) team = Team.query.filter( Team.courseId == course.CourseId).order_by( Team.TeamNumber.desc()).first() member = Member() member.studentId = userId member.teamId = team.TeamNumber member.votenum = 0 db.session.add(member) return redirect('/student/display')
def sign_up(): username = request.values.get('userName') pwd = request.values.get('pwd') nickname = request.values.get('nickname') sex = request.values.get('sex') mobile = request.values.get('mobile') birthday = request.values.get('birthday') portrait = request.values.get('portrait') with db.Session() as session: rs = session.query(Member.username).filter( db.and_(Member.username == username)).all() if len(rs) != 0: return jsonify(dict(statusCode="401")) else: session.add( Member( username=username, password=pwd, nickname=nickname, sex=Member.SEX_FEMALE if sex == "F" else Member.SEX_MALE, mobile=mobile, birthday=datetime.datetime.strptime(birthday, "%Y-%m--%d"), portrait=portrait, # 应当是一个图片 created_dt=datetime.datetime.now(), valid=Member.VALID_VALID)) session.add( MemberLog(username=username, action=MemberLog.ACTION_INSERT)) return jsonify(dict(statusCode="200", sessionKey=""))
def get_member(): with Student.auto_commit(): member = Member("Mario", 3.0, '*****@*****.**', 'A', '123456') # 数据库的insert操作 Student.session.add(member) return 'hello member'
def login(): ctx = {'code': 1, 'msg': "成功",'data': {}} nickname = request.form.get("nickname") gender = request.form.get("gender") avatarurl = request.form.get("avatarur") code = request.form.get("code") if not code or len(code) <1: ctx['code'] = -1 ctx['msg'] = '获取openid出错' return jsonify(ctx) opneid =MemberService.getOpenId(code) if not opneid: ctx['code'] = -1 ctx['msg'] = 'code无效' return jsonify(ctx) app_id = current_app.config.get('APP_ID') app_secret= current_app.config.get('app_secret') ctx['data']['nickname'] = nickname url = 'https://api.weixin.qq.com/sns/jscode2session?appid=%swx4503a4f6af272145&secret=%s&js_code=%s&grant_type=authorization_code'%(code,app_id,app_secret) response = request.get(url) opneid = response.json().get('openid') oauthmemberbind = OauthMemberBind.query.filter_by(opneid=opneid).first() #存数据库 if not oauthmemberbind: member = Member() member.nickname = nickname member.avatar =avatarurl member.gender =gender member.salt =MemberService.getSalt() db.session.add(member) db.session.commit() oauthmemberbind= OauthMemberBind oauthmemberbind.openid = opneid oauthmemberbind.client_type = 'wx' oauthmemberbind.type = 1 oauthmemberbind.member_id = member.id db.session.add(oauthmemberbind) db.session.commit() token = MemberService.geneAuthCode(member) ctx['data']['token'] = '%s#%s'%(member.id,token) return jsonify(ctx) else: member = Member.query.get(oauthmemberbind.member_id) token = MemberService.geneAuthCode(member) ctx['data']['token'] = '%s#%s' % (member.id, token) return jsonify(ctx)
def get(self): result = [] len_sysonline = Member().getAll()[0] len_sysonline = dict(len_sysonline) for keys, values in len_sysonline.items(): args = {} args['id'] = keys args['numbers'] = values result.append(args) results = {"success": True, "data": result} return results
def get(self, id): sysonline = SysadminOnline().getdate(id) bank = SystemBankAccount().getdate(id) # len_sysonline = Member().getLen(id)[0][0][0] len_sysonline = Member().getLen(id)[0] len_sysonline = dict(len_sysonline) sysonline = dict(sysonline[0]) bank = dict(bank[0]) result_sysonline = [] sysonline_args = {} result_bank = [] bank_args = {} result_numbers = [] numbers_args = {} for key, values in sysonline.items(): result_one = {} result_one['id'] = key result_one['names'] = values result_sysonline.append(result_one) sysonline_args['sysonline'] = result_sysonline for key, values in bank.items(): result_one = {} result_one['id'] = key result_one['names'] = values result_bank.append(result_one) bank_args['bank'] = result_bank keys = [] result_one = {} for key, values in len_sysonline.items(): keys.append(key) if 1 not in keys: result_one['numbers1'] = 0 result_numbers.append(result_one) if 0 not in keys: result_one['numbers0'] = 0 result_numbers.append(result_one) if 9 not in keys: result_one['numbers9'] = 0 result_numbers.append(result_one) if 10 not in keys: result_one['numbers10'] = 0 result_numbers.append(result_one) if 11 not in keys: result_one['numbers11'] = 0 result_numbers.append(result_one) numbers = 'numbers{}'.format(key) result_one[numbers] = values result = { "success": True, "data": [sysonline_args, bank_args, result_one] } return result
def create_default_member(): from app.models import db from app.models.member import Member member = Member() member.type = 9 member.username = '******' member.password = '******' try: db.session.add(member) db.session.commit() except: db.session.rollback() db.session.remove()
def login(): res = {'code': 1, 'msg': '成功', 'data': {}} nickName = request.form.get('nickName') avataUrl = request.form.get('avataUrl') gender = request.form.get('gender') code = request.form.get('code') print(nickName, avataUrl, gender, code) if len(code) < 1: res['code'] = -1 res['msg'] = 'code有误' return jsonify(res) if not all([nickName, avataUrl, gender, code]): res['code'] = -1 res['msg'] = '参数有误' return jsonify(res) # 获取open_id open_id = memberService.getOpenid(code) if not open_id: res['code'] = -1 res['msg'] = '获取open_id出错' return jsonify(res) #存数据库去重 oauthMemberBind = OauthMemberBind.query.filter_by(openid=open_id).first() if not oauthMemberBind: member = Member() member.nickname = nickName member.avatar = avataUrl member.gender = gender member.salt = memberService.getSalt() db.session.add(member) db.session.commit() Oauth_member_bind = OauthMemberBind() Oauth_member_bind.openid = open_id Oauth_member_bind.client_type = 'wx' Oauth_member_bind.type = 1 Oauth_member_bind.member_id = member.id db.session.add(Oauth_member_bind) db.session.commit() member = Member.query.get(oauthMemberBind.member_id) #生成前端所需要的token token = "%s#%s" % (memberService.geneAuthCode(member), member.id) res['data']['token'] = token return jsonify(res)
def join(): if session.get("id") is None: return redirect("/user/login") name = session.get("name") teamId = request.args.get("id") team = Team.query.filter_by(TeamNumber=teamId).first() #查询该成员是否满员,如果满员禁止加入 if team.isFinish == 1: return render_template('student_templates/viewinvitation.html', name=name, message="该小组满员了") courseId = CourseAndStudent.query.filter_by( studentId=session.get("id")).first().CourseId totalNum = Course.query.filter_by(CourseId=courseId).first().numofmember with db.auto_commit(): memberr = Member() memberr.teamId = teamId memberr.studentId = session.get("id") memberr.votenum = 0 db.session.add(memberr) countMember = Member.query.filter_by(teamId=teamId).count() if totalNum == countMember: team.isFinish = 1 db.session.commit() invitelst = Invite.query.filter_by(inviteId=session.get("id")).delete() #检查该小组是否满员,满员则设置为isFInish=1 #如果成功加入小组,则清除邀请信息 invitelst = Invite.query.filter(Invite.inviteId == session.get("id")) result = [] for i in invitelst: dict1 = {} studentname = Student.query.filter( Student.id == i.inviteeId).first().name dict1['info'] = studentname dict1['teamId'] = i.teamId result.append(dict1) return render_template('student_templates/viewinvitation.html', name=name, result=result)
def post(self): parser = RequestParser(trim=True) parser.add_argument('username', type=str, required=True) args = parser.parse_args(strict=True) try: member = Member() member.type = 9 member.username = args['username'] member.registrationTime = time_to_value() member.registrationHost = host_to_value(request.remote_addr) db.session.add(member) db.session.commit() except: db.session.rollback() db.session.remove() abort(500) return make_response([]), 201
def byStudent(): if session.get("id") is None: return redirect("/user/login") name=session.get("name") courseId=request.args.get("courseId") studentList=CourseAndStudent.query.filter_by(CourseId=courseId).all() list=[] for i in studentList: student=Student.query.filter_by(id=i.studentId).first() if student is not None: list.append(student) #每组的人数 totalNum=Course.query.filter_by(CourseId=courseId).first().numofmember #组的数量 # teamNum=len(list)/totalNum+1 # print(teamNum) # # if teamNum==1: # list2=[] # list2.append(list) # pass # else: from random import shuffle shuffle(list) # 重排序 list2 = [] for i in range(0, len(list), totalNum): list2.append(list[i:i + totalNum]) result=[] for i in list2: dict1 = dict() nameTeam=random.randint(100,1000) dict1["name"]=str(nameTeam) dict1["value"]=i print(i) result.append(dict1) with db.auto_commit(): team = Team() team.TeamName=str(nameTeam) team.courseId=courseId # 数据库的insert操作 db.session.add(team) team=Team.query.filter(Team.courseId==courseId).filter(Team.TeamName==nameTeam).first() with db.auto_commit(): for x in i: member=Member() member.teamId=team.TeamNumber member.studentId=x.id db.session.add(member) Course.query.filter(Course.CourseId == courseId).update({"teamType": 2}) db.session.commit() return render_template("teacher_templates/displaygroup.html",name=name,courseId=courseId,result=result)
def post(self): member_parser = RequestParser(trim=True) member_parser.add_argument('username', type=str) member_parser.add_argument('password', type=str, default=DEFAULT_MEMBER_PASSWORD) member_parser.add_argument('fundPassword', type=str, default=DEFAULT_MEMBER_FUND_PASSWORD) member_parser.add_argument('parentUsername', type=str) member_parser.add_argument('commissionConfig', type=int) member_parser.add_argument('defaultRebateConfig', type=int) member_parser.add_argument('defaultLevelConfig', type=int) member_parser.add_argument('type', type=int) member_parser.add_argument('rebateRate', type=float) member_args = member_parser.parse_args() member_personal_info_parser = RequestParser(trim=True) member_personal_info_parser.add_argument('name', type=str) member_personal_info_parser.add_argument('birthdate', type=str) member_personal_info_parser.add_argument('gender', type=int) member_personal_info_parser.add_argument('phone', type=str) member_personal_info_parser.add_argument('email', type=str) member_personal_info_parser.add_argument('tencentQQ', type=str) member_personal_info_parser.add_argument('tencentWeChat', type=str) member_personal_info_parser.add_argument('personalInfoRemark', type=str, dest='remark') member_personal_info_args = member_personal_info_parser.parse_args() pattern = "^[A-Za-z0-9\\u4e00-\\u9fa5][A-Za-z0-9\\u4e00-\\u9fa5-_]{4,13}[A-Za-z0-9\\u4e00-\\u9fa5]$" if member_args['type'] is not None: if member_args['type'] == 1: re_result = re.match(pattern, member_args['username']) if re_result is None: return make_response(error_code=400, error_message="账号必须为6-15位字母和数字组合") if member_personal_info_args['birthdate'] is None or len(member_personal_info_args['birthdate']) == 0: member_personal_info_args['birthdate'] = None else: timeArray = time.strptime(member_personal_info_args['birthdate'], "%Y-%m-%d") timestamp = time.mktime(timeArray) member_personal_info_args['birthdate'] = int(timestamp) member_personal_info_args = {key: value for key, value in member_personal_info_args.items() if value} member_bank_account_parser = RequestParser(trim=True) member_bank_account_parser.add_argument('bankId', type=str) member_bank_account_parser.add_argument('accountNumber', type=str) member_bank_account_parser.add_argument('accountName', type=str) member_bank_account_parser.add_argument('subbranchName', type=str) member_bank_account_parser.add_argument('province', type=str) member_bank_account_parser.add_argument('city', type=str) member_bank_account_parser.add_argument('bankAccountRemark', type=str, dest='remark') member_bank_account_args = member_bank_account_parser.parse_args() if member_args['type'] is None or member_args['type']=='' or member_args['type']=="": return { 'errorCode': "9998", 'errorMsg': "代理层级不能为空", 'success': False } if member_args['username'] is None or member_args['username']=='' or member_args['username']=="": return { 'errorCode': "9998", 'errorMsg': "用户名不能为空", 'success': False } if member_args['type'] != 11: if member_args['parentUsername'] is None or member_args['parentUsername']=='' or member_args['parentUsername']=="": return { 'errorCode': "9998", 'errorMsg': "上层代理不能为空", 'success': False } if member_args['commissionConfig'] is None or member_args['commissionConfig']=='' or member_args['commissionConfig']=="": return { 'errorCode': "9998", 'errorMsg': "佣金设定不能为空", 'success': False } if member_args['type'] == 1: if member_args['defaultRebateConfig'] is None or member_args['defaultRebateConfig']=='' or member_args['defaultRebateConfig']=="": return { 'errorCode': "9998", 'errorMsg': "预设反水不能为空", 'success': False } if member_args['defaultLevelConfig'] is None or member_args['defaultLevelConfig']=='' or member_args['defaultLevelConfig']=="": return { 'errorCode': "9998", 'errorMsg': "预设会员等级不能为空", 'success': False } if member_args['type'] == 1: parent = Member.query.filter(Member.username == member_args['parentUsername'],Member.type==9).first() if parent is None: return { 'errorCode': "9998", 'errorMsg': "上层代理错误", 'success': False } if member_args['type'] == 9: if 'defaultRebateConfig' in member_args: del member_args['defaultRebateConfig'] if 'defaultLevelConfig' in member_args: del member_args['defaultLevelConfig'] parent = Member.query.filter(Member.username == member_args['parentUsername'],Member.type==10).first() if parent is None: return { 'errorCode': "9998", 'errorMsg': "上层代理错误", 'success': False } if member_args['type'] == 10: if 'defaultRebateConfig' in member_args: del member_args['defaultRebateConfig'] if 'defaultLevelConfig' in member_args: del member_args['defaultLevelConfig'] parent = Member.query.filter(Member.username == member_args['parentUsername'],Member.type==11).first() if parent is None: return { 'errorCode': "9998", 'errorMsg': "上层代理错误", 'success': False } if member_args['type'] == 11: if 'defaultRebateConfig' in member_args: del member_args['defaultRebateConfig'] if 'defaultLevelConfig' in member_args: del member_args['defaultLevelConfig'] if member_args['parentUsername'] is not None: return { 'errorCode': "9998", 'errorMsg': "该级没有上层代理,不可设置", 'success': False } if member_bank_account_args['bankId'] is None or len(member_bank_account_args['bankId']) == 0: member_bank_account_args['bankId'] = None else: member_bank_account_args['bankId'] = int(member_bank_account_args['bankId']) member_bank_account_args = {key: value for key, value in member_bank_account_args.items() if value} member = Member.query.filter(Member.username == member_args['username']).first() if member: return make_response(error_message='用户名已存在') if member_args['parentUsername'] is not None: parent = Member.query.filter(Member.username == member_args.pop('parentUsername')).first() if parent.status == 0: return jsonify({ 'success': False, 'errorCode': 403, 'errorMsg': '该代理已被停用' }) if member_args['rebateRate']: m_boolean = member_args['rebateRate'] <= parent.rebateRate or member_args['rebateRate']==0 if not m_boolean: return make_response(error_code=400, error_message="返点率不能超过" + str(float(parent.rebateRate)) + "%") else: return make_response(error_code=400, error_message="请设置返点") if member_args['type'] != 11: if not parent or not parent.type: return make_response(error_message='上级用户名错误') if parent.parents is None: parents = '%s' % parent.id parentsInfo = '%s' % parent.username else: parents = parent.parents + ',%s' % parent.id parentsInfo = parent.parentsInfo + ',%s' % parent.username member_args['parent'] = parent.id member_args['parents'] = parents member_args['parentsInfo'] = parentsInfo member_args['levelConfig'] = parent.defaultLevelConfig member_args['rebateConfig'] = parent.defaultRebateConfig # #暂时以这种情况新增反水设定 # member_args['defaultLevelConfig'] = parent.defaultLevelConfig # member_args['defaultLevelConfig'] = parent.defaultLevelConfig else: member_args['parent'] = None member_args['parents'] = None member_args['parentsInfo'] = None member_args['levelConfig'] = None member_args['rebateConfig'] = None else: member_args.pop('parentUsername') try: member_args['registrationTime'] = time_to_value() member_args['agentsTime'] = time_to_value() member_args['registrationHost'] = host_to_value(request.remote_addr) member = Member(**member_args) db.session.add(member) db.session.commit() OperationHistory().PublicMemberDatasApply(2001, member.id) try: member_personal_info_args['id'] = member.id member_personal_info = MemberPersonalInfo(**member_personal_info_args) if any(member_bank_account_args.values()): member_bank_account_args['memberId'] = member.id member_bank_account = MemberBankAccount(**member_bank_account_args) member_bank_account_args['userId'] = g.current_user.id member_bank_account_args['time'] = time_to_value() member_bank_account_modification_log = MemberBankAccountModificationLog(**member_bank_account_args) db.session.add(member_bank_account) db.session.add(member_bank_account_modification_log) db.session.add(member_personal_info) db.session.commit() OperationHistory().PublicMemberDatasApply(1002, member.id) OperationHistory().PublicMemberDatasApply(1003, member.id) except: db.session.rollback() db.session.remove() db.session.delete(member) db.session.commit() abort(500) except: db.session.rollback() db.session.remove() abort(500) return make_response([]), 201
def insert_member(room_id, user_id): member = Member(room_id=room_id, user_id=user_id) session.add(member) session.commit()
def make_member(self, data, **kwargs): return Member(**data)
def enter_room(room_id, uid): delete_room() exist_room = Room.query.filter_by(room_id=room_id).first() if exist_room is None: send_message(uid, '房间不存在,请法官重新建房。') return room_owner = exist_room.owner_name owner_id = exist_room.owner_id num = exist_room.num bad_number = exist_room.bad_number white_number = exist_room.white bad_number = bad_number.split(',') bad_num = len(bad_number) good_word = exist_room.good_word bad_word = exist_room.bad_word if uid == owner_id: send_message(uid, '法官凑什么热闹。') return has_come = Member.query.filter_by(room_id=room_id, uid=uid).first() if has_come is not None: your_number = has_come.index if white_number != -1 and your_number == white_number: word = '' else: if str(your_number) in bad_number: word = bad_word else: word = good_word message = wrap_enter_message(room_id, room_owner, word, has_come.index, bad_num, num, white_number) send_message(uid, message) return member = Member(room_id, uid) db.session.add(member) db.session.commit() room_members = Member.query.filter_by(room_id=room_id).all() room_members = sorted(room_members, key=lambda x: x.enter_time) index = -1 for i, m in enumerate(room_members): if m.uid == uid: index = i if index >= num: db.session.delete(room_members[index]) db.session.commit() send_message(uid, '房间人数已满') return your_number = index + 1 if white_number != -1 and your_number == white_number: word = '' else: if str(your_number) in bad_number: word = bad_word else: word = good_word member.index = your_number db.session.add(member) db.session.commit() message = wrap_enter_message(room_id, room_owner, word, your_number, bad_num, num, white_number) send_message(uid, message)