Exemple #1
0
 def get(self, phone, code_type, **kwargs):
     # phone = self.get_argument('phone')
     '''
     :发送手机验证码
     :param phone:
     :param code_type:   _reg:注册(登陆)验证码
     :param kwargs:
     :return:
     '''
     if not phone or not code_type:
         data = {'stat': '1001', 'info': '请求参数错误'}
     else:
         if not Regular.check_phone(phone):
             data = {'stat': '1001', 'info': '手机格式不正确'}
         else:
             cache_key = str(phone) + str(code_type)
             code = create_random_passwd(2)
             if self.mcache.get(cache_key):
                 self.mcache.set(cache_key, self.mcache.get(cache_key), 180)
                 data = {'stat': '1000', 'info': '操作成功'}
             else:
                 is_ok = self.mcache.set(cache_key, str(code), 180)
                 if code_type == '_reg':
                     content = PHONE_REG_TEMPLATE % (code)
                 elif code_type == '_login':
                     content = PHONE_LOGIN_TEMPLATE % (code)
                 else:
                     content = CHECK_CODE_TEMPLATE % (code)
                 if is_ok:
                     send_phone_msg(str(phone), content)
                     data = {'stat': '1000', 'info': '发送成功'}
                 else:
                     data = {'stat': '1001', 'info': 'memcache存储验证码失败'}
     self.write_json(data)
Exemple #2
0
 def get(self, *args, **kwargs):
     phone = self.get_argument('phone')
     code = create_random_passwd(2)
     if self.mcache.get(str(phone) + '_reg'):
         self.mcache.set(
             str(phone) + '_reg', self.mcache.get(str(phone) + '_reg'), 180)
         data = {'stat': '1000', 'info': '操作成功'}
     else:
         is_ok = self.mcache.set(str(phone) + '_reg', str(code), 180)
         content = PHONE_REG_TEMPLATE % (code)
         if is_ok:
             send_phone_msg(str(phone), content)
             data = {'stat': '1000', 'info': '操作成功'}
         else:
             data = {'stat': '1001', 'info': '操作失败'}
     self.write_json(data)
Exemple #3
0
    def post(self, *args, **kwargs):

        self.get_paras_dict()
        phone = self.qdict.get('phone')
        code = self.qdict.get('code')
        password = self.qdict.get('password')
        next = self.get_argument('next', '/')
        user_service.set_db(self.db)
        try:
            for key in ['phone', 'code']:
                if not self.qdict.get(key):
                    raise SiteError('参数错误')
            cache_code = self.mcache.get(
                str(self.qdict.get('phone')) + '_code')
            if str(cache_code) == code.strip():
                user = user_service.create_user_by_phone(phone,
                                                         password=password)
                cookies = user_service.user_format(user)
                open_id = self.get_secure_cookie('wx_login_open_id')
                nick = self.get_secure_cookie('nick')
                photo = self.get_secure_cookie('photo')
                data = self.child_account_key(user)
                if open_id:
                    user.Fweixin = open_id
                if nick and not user.Fnick_name:
                    user.Fnick_name = nick
                if photo and (user.Fphoto_url == '/static/common/images.png'
                              or not user.Fphoto_url):
                    user.Fphoto_url = photo
                if data:
                    cookies.update(data)
                if not user.Fnick_name:
                    user.Fnick_name = '公主号_' + create_random_passwd(3)
                self.set_secure_cookie('loginuser',
                                       ujson.dumps(cookies),
                                       expires_days=10)
                self.db.add(user)
                self.db.commit()
                # url = self.get_cookie('login_regrdiect_url')
                data = {'stat': '1000', 'info': '验证通过并登陆', 'data': {}}
            else:
                data = {'stat': '1004', 'info': '验证码错误'}
        except Exception, e:
            pass
            data = {'stat': '1005', 'info': '程序异常,异常原因是' + e.message}
Exemple #4
0
    def create_user(self, user_name, mobile):
        user_service = UserServices(session)
        is_ok, info = user_service.registe_check_exist(phone=mobile)
        if not is_ok:
            user = session.query(Users).filter(
                Users.Fdeleted == 0, Users.Fuser_mobi == mobile).scalar()
            return True, user

        user = Users()
        user.Fuid = user_service.user_uid(user_name=mobile)
        user.Fuser_mobi = mobile
        user.Fnick_name = user_name
        user.Fstatus = 'normal'
        user.Fuser_pwd = user_service.user_passed(create_random_passwd(3),
                                                  user.Fuid)
        user.is_employee = 0
        user_service.db.add(user)
        user_service.db.commit()
        return True, user
Exemple #5
0
    def create_user_and_send_msg(self, album, args, order):
        '''
        :todo 创建用户并更新到相册信息 同时发送万丈秘法
        :param album:
        :param args:
        :return:
        '''
        user_service.set_db(self.db)
        passwd = create_random_passwd(3)
        content = PASSWD_TEMPLATE % (self.get_current_user().get(
            'Fcompany_name', ''), args.get('user_mobi'), passwd)
        is_success, is_create, user = user_service.create_user_by_order(
            args.get('user_mobi'), passwd, args.get('user_name'))
        if is_create:
            send_phone_msg(args.get('user_mobi'), content)

        if user and user.Fweixin:
            try:
                template = WEIXIN_TEMPLATES.get('new_order_confirm')
                page_cache = PageDataCache(self.db)
                access_token = page_cache.get_access_token(
                    setting.WX_GZH_AppID, setting.WX_GZH_AppSecret)
                send_msg_to_owner(
                    access_token,
                    user.Fweixin,
                    template.get('jsonText'),
                    link=str(
                        'http://m.gongzhuhao.com/mobile/20151985112504291695293/schedules'
                    ),
                    template_id=template.get('TEMPLATE_ID'),
                    first=str('尊敬的{0},您在“{1}”的生成了一条新订单,详细信息如下:'.format(
                        order.Fuser_name,
                        self.get_current_user().get('Fcompany_name', ''))),
                    keyword1=str(order.Forder_id_user),
                    keyword2=str(_TYPE_ORDER[order.Forder_type]),
                    keyword3='****',
                    keyword4=str(
                        datetime_format(input_date=order.Fcreate_time)),
                    keyword5=str(album.Fablum_name),
                    remark='祝您心情愉快,点击查看排期详情')
            except Exception, e:
                print e.message
 def create_user_and_send_msg(self, album, args):
     '''
     :todo 创建用户并更新到相册信息 同时发送万丈秘法
     :param album:
     :param args:
     :return:
     '''
     user_service.set_db(self.db)
     passwd = create_random_passwd(6)
     content = PASSWD_TEMPLATE % (self.get_current_user().get(
         'Fcompany_name', ''), passwd, args.get('user_mobi'))
     is_success, is_create, user = user_service.create_user_by_order(
         args.get('user_mobi'), passwd, args.get('user_name'))
     if is_create:
         send_phone_msg(args.get('user_mobi'), content)
     if user:  # 相册更新用户Id
         album.Fuser_id = user.Fid
         self.db.add(album)
         self.db.commit()
         return user.Fid