コード例 #1
0
 def set_company(self, arguments):
     """
     设置session的companyId
     """
     company_id = current_user['company_id'][0]
     if arguments['cId'] and Company.find_one(
         {'company_id': int(arguments['cId'])}):
         company_id = arguments['cId']
     session["current_company"] = company_id
     session["current_user_company"] = Company.company_find_one(
         {'company_id': int(company_id)})
     return self.done(company_id)
コード例 #2
0
    def new_register(self, arguments):
        """
        @apiVersion 1.0.0
        @api {post} /api/V1/user/new_register 新的注册接口
        @apiName new_register
        @apiGroup User

        @apiParam {int} mobile 用户手机号
        @apiParam {int} company_name 公司名称
        """
        mobile = arguments['mobile']
        if User.find_one({'mobile': mobile}):
            return self.fail(message=u"该手机号码已注册")
        password = str(mobile)
        company_name = arguments['company_name']
        company = Company.find_one({'company_name': company_name})
        if company:
            return self.fail(message=u"该公司已存在")
        else:
            new_company = Company.create_company(company_name)
            company_id = new_company['company_id']
        for item in ['mobile', 'company_name']:
            del arguments[item]
        user = User.create_user(int(mobile), password, [company_id],
                                **arguments)
        Company.update_one({'_id': new_company['_id']},
                           {'$set': {
                               'admin': user['uid']
                           }})
        permission = {str(company_id): {'shouzu': '允许', 'zhaozu': '允许'}}
        User.update_one({'uid': user['uid']},
                        {'$set': {
                            'permission': permission
                        }})
        user = load_user(user['uid'])
        login_user(user, remember=True)
        session["current_company"] = company_id
        session["current_user_company"] = Company.company_find_one(
            {'company_id': int(company_id)})
        return self.done("success")