def test(request, *args, **kwargs): """ 优化缓存结果的非空判断 by:王健 at:2015-05-21 修改控制校验 by:王健 at:2015-05-21 增加删除MY_PROJECT_QUERY_LIST缓存 by:尚宗凯 at:2015-07-01 欠费时为管理员和超级管理员发消息 """ project_id = int(kwargs.get('project_id')) if project_id == settings.SHOW_PROJECT_ID: return func(request, *args, **kwargs) today = timezone.now().strftime('%Y-%m-%d') project_active = cache.get(PROJECT_IS_ACTIVE % (project_id, today)) if project_active is None: record_list = ProjectPersonChangeRecord.objects.filter(project_id=project_id).order_by('-create_date')[:1] if len(record_list) > 0: pre = record_list[0] else: pre = None project_active = 1 # 不可用 if pre: project_active = pre.commit_days_real() + 2 if project_active < 1: if Project.objects.filter(pk=project_id).exists(): p = Project.objects.get(pk=project_id) p.status = 1 p.save() receiver_user_ids = [i.pk for i in p.group_set.filter(Q(type="root")|Q(type="sys_manage"))] NeedMessage.create_multiple_sys_message(receiver_user_ids, "title", SYS_MESSAGE['project_arrears'] % (p.total_name)) cache.set(PROJECT_INFO % project_id, MyEncoder.default(p), settings.CACHES_TIMEOUT) cache.delete(MY_PROJECT_QUERY_LIST % request.user.pk) cache.set(PROJECT_IS_ACTIVE % (project_id, today), project_active, settings.CACHES_TIMEOUT) if project_active and project_active > 1: return func(request, *args, **kwargs) else: return getResult(False, u'%s 的可使用额度不足,请续费后继续使用。' % Project.objects.get(pk=kwargs.get('project_id')).total_name, None, 7)
def reg_user(request): """ 注册新用户 by:王健 at:2015-1-3 所有用户名都改为tel by:王健 at:2015-1-8 手机校验码 校验 by:王健 at:2015-1-14 注册时带上手机校验码,和手机号匹配 by:王健 at:2015-1-14 修改个人信息返回值 by:王健 at:2015-1-20 修改默认姓名 by:王健 at:2015-3-17 添加注册的手机号已经被邀请过的逻辑 by:尚宗凯 at:2015-3-25 flag 拉人 暂时去掉 by:王健 at:2015-3-25 session中存在的用户,如果没有手机号,直接覆盖 by:王健 at:2015-4-6 可以拉多个人 by:尚宗凯 at:2015-4-8 增加发送系统消息 by:尚宗凯 at:2015-04-10 解决NSPersonTel里面 tel project_id 不唯一问题 by:王健 at:2015-05-18 修改发送need消息 by:尚宗凯 at:2015-05-07 改下提示内容 by:尚宗凯 at:2015-05-12 短信验证码使用后从session中删除 by: 范俊伟 at:2015-07-01 """ flag = request.REQUEST.has_key('flag') if flag and not Project.objects.filter(flag=request.REQUEST.get('flag')).exists(): return getResult(False, u'邀请链接已经失效,请联系项目管理员,重新获得邀请。') if request.user.is_anonymous() or (hasattr(request.user, 'tel') and request.user.tel): user = get_user_model()() elif not request.user.tel: user = request.user if request.REQUEST.has_key('password'): user.set_password(request.REQUEST.get('password')) code = request.REQUEST.get('code', '') tel = request.REQUEST.get('tel', '') smsdebug = request.REQUEST.get('smsdebug', '') if not smsdebug and code != request.session.get('smscode', '1234'): return getResult(False, u'手机验证码不对,请重新输入。', None) if not smsdebug and tel != request.session.get('smstel', ''): return getResult(False, u'发送验证码的手机号,和注册的手机号不符合。请重新输入', None) user.tel = tel if not user.tel or get_user_model().objects.filter(tel=user.tel).exists(): return getResult(False, u'手机号已经存在。请更换手机号', None) # user.icon = request.REQUEST.get('userhead', '') user.name = request.REQUEST.get('name', u'') # {'success': True, 'message': u'用户名已经存在', 'result': None} user.save() request.session['smscode'] = None # send_mail(u'邮箱验证--%s' % APP_NAME, u'请点击下方链接,完成注册', user.email) # user.email_user(u'邮箱验证--%s' % APP_NAME, u'请点击下方链接,完成注册') if NSPersonTel.objects.filter(tel=tel).exists(): pts = NSPersonTel.objects.filter(tel=tel) s = set() for pt in pts: if (pt.tel, pt.project_id) in s: continue person = Person() person.user = user person.project = pt.project person.save() s.add((pt.tel, pt.project_id)) if Group.objects.filter(id=pt.group.pk).exists(): group = pt.group group.look_members.add(person.user) pt.delete() # if flag: # project = Project.objects.get(flag=request.REQUEST.get('flag')) # person = Person() # person.user = user # person.project = project # person.save() # group = Group.objects.get(project=project, flag='root') # group.look_members.add(person) # group.save() NeedMessage.create_sys_message(user.pk,"title",SYS_MESSAGE['reg_user']) user.backend = 'django.contrib.auth.backends.ModelBackend' auth_login(request, user) return getResult(True, u'注册成功', user.get_user_map(True))
def reg_user(request): """ 注册新用户 by:王健 at:2015-1-3 所有用户名都改为tel by:王健 at:2015-1-8 手机校验码 校验 by:王健 at:2015-1-14 注册时带上手机校验码,和手机号匹配 by:王健 at:2015-1-14 修改个人信息返回值 by:王健 at:2015-1-20 修改默认姓名 by:王健 at:2015-3-17 添加注册的手机号已经被邀请过的逻辑 by:尚宗凯 at:2015-3-25 flag 拉人 暂时去掉 by:王健 at:2015-3-25 session中存在的用户,如果没有手机号,直接覆盖 by:王健 at:2015-4-6 可以拉多个人 by:尚宗凯 at:2015-4-8 增加发送系统消息 by:尚宗凯 at:2015-04-10 解决NSPersonTel里面 tel project_id 不唯一问题 by:王健 at:2015-05-18 修改发送need消息 by:尚宗凯 at:2015-05-07 改下提示内容 by:尚宗凯 at:2015-05-12 短信验证码使用后从session中删除 by: 范俊伟 at:2015-07-01 """ flag = request.REQUEST.has_key('flag') if flag and not Project.objects.filter( flag=request.REQUEST.get('flag')).exists(): return getResult(False, u'邀请链接已经失效,请联系项目管理员,重新获得邀请。') if request.user.is_anonymous() or (hasattr(request.user, 'tel') and request.user.tel): user = get_user_model()() elif not request.user.tel: user = request.user if request.REQUEST.has_key('password'): user.set_password(request.REQUEST.get('password')) code = request.REQUEST.get('code', '') tel = request.REQUEST.get('tel', '') smsdebug = request.REQUEST.get('smsdebug', '') if not smsdebug and code != request.session.get('smscode', '1234'): return getResult(False, u'手机验证码不对,请重新输入。', None) if not smsdebug and tel != request.session.get('smstel', ''): return getResult(False, u'发送验证码的手机号,和注册的手机号不符合。请重新输入', None) user.tel = tel if not user.tel or get_user_model().objects.filter(tel=user.tel).exists(): return getResult(False, u'手机号已经存在。请更换手机号', None) # user.icon = request.REQUEST.get('userhead', '') user.name = request.REQUEST.get('name', u'') # {'success': True, 'message': u'用户名已经存在', 'result': None} user.save() request.session['smscode'] = None # send_mail(u'邮箱验证--%s' % APP_NAME, u'请点击下方链接,完成注册', user.email) # user.email_user(u'邮箱验证--%s' % APP_NAME, u'请点击下方链接,完成注册') if NSPersonTel.objects.filter(tel=tel).exists(): pts = NSPersonTel.objects.filter(tel=tel) s = set() for pt in pts: if (pt.tel, pt.project_id) in s: continue person = Person() person.user = user person.project = pt.project person.save() s.add((pt.tel, pt.project_id)) if Group.objects.filter(id=pt.group.pk).exists(): group = pt.group group.look_members.add(person.user) pt.delete() # if flag: # project = Project.objects.get(flag=request.REQUEST.get('flag')) # person = Person() # person.user = user # person.project = project # person.save() # group = Group.objects.get(project=project, flag='root') # group.look_members.add(person) # group.save() NeedMessage.create_sys_message(user.pk, "title", SYS_MESSAGE['reg_user']) user.backend = 'django.contrib.auth.backends.ModelBackend' auth_login(request, user) return getResult(True, u'注册成功', user.get_user_map(True))