def create_user_and_person(tel, name,nickname, sex, project, title, group, group_type): """ 根据电话号用户名生成nsuser和person by:尚宗凯 at:2015-3-3 修改project id by:尚宗凯 at:2015-4-14 修改生成email的方式 by:尚宗凯 at:2015-06-25 """ if tel: tel = int(tel) tel += 1000 tel = str(tel) user = create_user_by_tel_name(tel, name, nickname, sex) person = Person() person.user = user person.project = project person.save() userinfo = UserInfo() userinfo.user = user userinfo.title = title userinfo.address = 101120101 userinfo.xueli = generate_xueli(title) #userinfo.company = u'依子轩软件科技有限公司' userinfo.qq = generate_qq() userinfo.email = generate_email(userinfo.qq) userinfo.birthday = generate_birthday(title) userinfo.save() grp = Group.objects.get(project_id=project.pk,name=group) assert group_type in ('1','0') if group_type == '1': print user grp.say_members.add(user) else: print user grp.look_members.add(user) return user
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 create_project(user, name, totalname): """ 创建项目 by:王健 at:2015-1-21 恢复total_name 字段 by:王健 at:2015-2-2 分组排序字段修改 by:王健 at:2015-2-3 创建项目 基础信息,增加社会大众通道 by:王健 at:2015-2-16 增加环信群组的属性 by:王健 at:2015-2-27 修改负责人长度 by:王健 at:2015-3-5 添加默认 地址 by:王健 at:2015-3-9 指定超级管理员 by:王健 at:2015-3-16 优化初始创建群聊 by:王健 at:2015-3-20 取消社会大众 分组 by:王健 at:2015-4-9 :param user: :return: """ project = Project() project.name = name project.total_name = totalname project.address = 101030100 project.jzmj = 50000 project.jglx = u'钢筋' project.jzcs = 3 project.htzj = 455732183 project.kg_date = '2015-01-10' project.days = 433 project.jsdw = u'建设单位%s' % user.tel project.jsdw_fzr = u'负责人%s' % user.tel[-1:] project.kcdw = u'勘察单位%s' % user.tel[-1:] project.kcdw_fzr = u'勘察%s' % user.tel[-1:] project.sjdw = u'设计单位%s' % user.tel[-1:] project.sjdw_fzr = u'设计%s' % user.tel[-1:] project.sgdw = u'施工单位%s' % user.tel[-1:] project.sgdw_fzr = u'施工%s' % user.tel[-1:] project.jldw = u'监理单位%s' % user.tel[-1:] project.jldw_fzr = u'监理%s' % user.tel[-1:] project.manager = user project.save() person = Person() person.user = user project.manager = user project.save() rootgroup = Group() rootgroup.user = user rootgroup.name = project.total_name rootgroup.type = 'root' rootgroup.project = project rootgroup.save() person.project = project person.save() rootgroup.say_members.add(person.user) group = Group() group.name = u'管理员' group.type = 'sys_manage' group.project = project group.sorted = 0 group.save() group.say_members.add(person.user) group = Group() group.name = u'行政主管' group.type = 'sys_xzzg' group.project = project group.sorted = 1 group.save() group = Group() group.name = u'建设单位' group.type = 'sys_jsdw' group.project = project group.sorted = 2 group.save() group = Group() group.name = u'设计单位' group.type = 'sys_sjdw' group.project = project group.sorted = 3 group.save() group = Group() group.name = u'勘察单位' group.type = 'sys_kcdw' group.project = project group.sorted = 4 group.save() group = Group() group.name = u'监理单位' group.type = 'sys_jldw' group.project = project group.sorted = 5 group.save() group = Group() group.name = u'施工单位' group.type = 'sys_sgdw' group.project = project group.sorted = 6 group.save() group = Group() group.name = u'项目经理部' group.type = 'sys_xmjl' group.project = project group.sorted = 7 group.is_needhx = True group.save() group.say_members.add(person.user) group.save() group = Group() group.name = u'劳务分包单位' group.type = 'sys_lwfbdw' group.project = project group.sorted = 8 group.save() group = Group() group.name = u'专业分包单位' group.type = 'sys_zyfbdw' group.project = project group.sorted = 9 group.save() # group = Group() # group.name = u'社会大众通道' # group.type = 'sys_shdztd' # group.project = project # group.sorted = 1000 # group.save() return project
def create_project_detail(user, p_detail): """ 创建项目 完全版 by:尚宗凯 at:2015-3-17 :param user: :param kwargs: :return: """ project = Project() project.name = p_detail['name'] project.total_name = p_detail['total_name'] project.address = p_detail['address'] project.jzmj = p_detail['jzmj'] project.jglx = p_detail['jglx'] project.jzcs = p_detail['jzcs'] project.htzj = p_detail['htzj'] project.kg_date = p_detail['kg_date'] project.days = p_detail['days'] # project.jsdw = u'建设单位%s' % user.tel # project.jsdw_fzr = u'负责人%s' % user.tel[-1:] # project.kcdw = u'勘察单位%s' % user.tel[-1:] # project.kcdw_fzr = u'勘察%s' % user.tel[-1:] # project.sjdw = u'设计单位%s' % user.tel[-1:] # project.sjdw_fzr = u'设计%s' % user.tel[-1:] # project.sgdw = u'施工单位%s' % user.tel[-1:] # project.sgdw_fzr = u'施工%s' % user.tel[-1:] # project.jldw = u'监理单位%s' % user.tel[-1:] # project.jldw_fzr = u'监理%s' % user.tel[-1:] project.jsdw = p_detail['jsdw'] project.jsdw_fzr = p_detail['jsdw_fzr'] project.kcdw = p_detail['kcdw'] project.kcdw_fzr = p_detail['kcdw_fzr'] project.sjdw = p_detail['sjdw'] project.sjdw_fzr = p_detail['sjdw_fzr'] project.sgdw = p_detail['sgdw'] project.sgdw_fzr = p_detail['sgdw_fzr'] project.jldw = p_detail['jldw'] project.jldw_fzr = p_detail['jldw_fzr'] project.manager = user project.save() person = Person() person.user = user project.manager = user project.save() rootgroup = Group() rootgroup.user = user rootgroup.name = project.total_name rootgroup.type = 'root' rootgroup.project = project rootgroup.save() person.project = project person.save() rootgroup.say_members.add(person.user) group = Group() group.name = u'管理员' group.type = 'sys_manage' group.project = project group.sorted = 0 group.save() group.say_members.add(person.user) group = Group() group.name = u'行政主管' group.type = 'sys_xzzg' group.project = project group.sorted = 1 group.save() group = Group() group.name = u'建设单位' group.type = 'sys_jsdw' group.project = project group.sorted = 2 group.save() group = Group() group.name = u'设计单位' group.type = 'sys_sjdw' group.project = project group.sorted = 3 group.save() group = Group() group.name = u'勘察单位' group.type = 'sys_kcdw' group.project = project group.sorted = 4 group.save() group = Group() group.name = u'监理单位' group.type = 'sys_jldw' group.project = project group.sorted = 5 group.save() group = Group() group.name = u'施工单位' group.type = 'sys_sgdw' group.project = project group.sorted = 6 group.save() group = Group() group.name = u'项目经理部' group.type = 'sys_xmjl' group.project = project group.sorted = 7 group.is_needhx = True group.save() group.say_members.add(person.user) group = Group() group.name = u'劳务分包单位' group.type = 'sys_lwfbdw' group.project = project group.sorted = 8 group.save() group = Group() group.name = u'专业分包单位' group.type = 'sys_zyfbdw' group.project = project group.sorted = 9 group.save() group = Group() group.name = u'社会大众通道' group.type = 'sys_shdztd' group.project = project group.sorted = 1000 group.save() return project
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))