Exemple #1
0
    def phone_regist(self):
        filter_emoji = Emoji.filter_emoji
        code = self.args["code"]
        phone = filter_emoji(self.args["phone"].strip())
        name = filter_emoji(self.args.get("name", "").strip())
        session = self.session
        exist_account = session.query(
            models.Accountinfo).filter_by(phone=phone).first()
        if exist_account:
            return self.send_fail("您已注册,如果您已是员工,请直接登录;如还不是员工请先使用手机号添加成为员工")

        check_msg_res = check_msg_token(phone, code, use="register")
        if not check_msg_res:
            return self.send_fail("验证码过期或者不正确")

        Accountinfo = models.Accountinfo
        account_info = Accountinfo(phone=phone, nickname=name, realname=name)

        session.add(account_info)
        session.flush()
        self.set_current_user(account_info, domain=ROOT_HOST_NAME)
        #每当有一个新用户注册的时候,就要对应的增加录入设置的信息
        Accountinfo.init_recorder_settings(session, account_info.id)
        session.commit()
        return self.send_success()
Exemple #2
0
	def post(self):
		#极验验证
		challenge = self.get_argument("geetest_challenge")
		validate = self.get_argument("geetest_validate")
		seccode = self.get_argument("geetest_seccode")
		# print (challenge,)
		# print (seccode)
		# print (validate,'validate')
		if len(challenge) <2 or len(seccode) <2 or len(validate) <2:
			return self.send_fail('请先完成图形验证')
		gt = geetest.geetest(captcha_id, private_key)
		result = gt.geetest_validate(challenge, validate, seccode)
		if not result:
			return self.send_fail('验证码错误')

		try:
			if_admin = self.session.query(models.ShopAdmin).filter_by(id=self.current_user.id,role=1).first()
		except:
			if_admin = None
		if if_admin:
			return self.send_fail("您已是卖家")
		#判断申请店铺的微信是否已是某店铺的管理员身份
		# try:
		# 	if_shopadmin = self.session.query(models.HireLink).join(models.ShopStaff,models.HireLink.staff_id == models.ShopStaff.id)\
		# 	.filter(models.HireLink.active==1,models.HireLink.work ==9 ,models.ShopStaff.id == self.current_user.id).first()
		# except:
		# 	if_shopadmin = None
		# try:
		# 	if_shop = self.session.query(models.Shop).filter_by(id = if_admin.shop_id).first()
		# except:
		# 	if_shop = None
		# if if_shopadmin:
		# 	return self.send_fail('该账号已是'+if_shop.shop_name+'的管理员,不能使用该账号申请店铺,若要使用该账号,请退出'+if_shop.shop_name+'管理员身份更换或其它账号')

		if not self.args['phone']:
			return self.send_fail("please input your phone number")
		if not self.args["realname"]:
			return self.send_fail("please input your realname")
		if not check_msg_token(phone=self.args['phone'], code=int(self.args["code"])):
			return self.send_fail(error_text="验证码过期或者不正确")

		if len(self.args["phone"])>11:
			return self.send_fail("手机号格式错误")
		if len(self.args["realname"])>20:
			return self.send_fail("真实姓名请不要超过20个字")
		if len(self.args["wx_username"])>20:
			return self.send_fail("微信号请不要超过20个字")

		if_normal_admin = self.session.query(models.ShopAdmin).filter_by(id=self.current_user.id).first()
		# print(if_normal_admin)
		self.current_user.accountinfo.phone=self.args["phone"]
		self.current_user.accountinfo.realname=self.args["realname"]
		self.current_user.accountinfo.wx_username=self.args["wx_username"]
		if if_normal_admin:
			if_normal_admin.role=1
			if_normal_admin.privileges = -1
		else:
			self.session.add(models.ShopAdmin(id=self.current_user.id))
		self.session.commit()
		return self.send_success()
Exemple #3
0
	def handle_checkcode(self):
		if not check_msg_token(phone = self.args["phone"], code=self.args["code"]):
		   return self.send_fail(error_text="验证码过期或者不正确")
		# password = self.args['password']
		# print(password)
		# if password:
		# 	self.current_user.accountinfo.update(self.session, phone=self.args["phone"],password=self.args["password"])
		# else:
		self.current_user.accountinfo.update(self.session, phone=self.args["phone"])
		return self.send_success()
Exemple #4
0
    def bind_phone(self):
        """绑定手机"""
        code = self.args["code"]
        phone = Emoji.filter_emoji(self.args["phone"].strip())

        if not self.current_user:
            return self.write_error(401)

        if len(phone) != 11:
            return self.send_fail("请填写正确的手机号")

        check_msg_res = check_msg_token(phone, code, use="bind")
        if not options.debug and not check_msg_res:
            return self.send_fail("验证码过期或者不正确")

        # 尝试合并账号
        success, errmsg = AuthFunc.merge_passport(
            self.session, self.current_user.passport_id, phone)
        if success:
            self.clear_current_user()
            return self.send_success()
        elif errmsg != "USE UPDATE":
            return self.send_fail(errmsg)

        # 尝试使用 UPDATE
        success, errmsg = AuthFunc.update_passportinfo(
            self.current_user.passport_id, "phone", phone)
        if not success:
            if errmsg == "NOT EXIST":
                return self.send_fail("账户不存在,请联系森果客服 400-027-0135")
            elif errmsg == "SAME VALUE":
                return self.send_fail("无需重复绑定")
            elif errmsg == "ALREADY BIND":
                return self.send_fail("该手机号已绑定,请更换手机号绑定或联系森果客服 400-027-0135")
            else:
                return self.send_fail("绑定失败,请联系森果客服 400-027-0135")

        self.current_user.phone = phone

        # 更新门店联系人 ID
        contacts = self.session.query(models.ShopContact) \
            .filter(models.ShopContact.phone == phone) \
            .all()
        if contacts:
            for contact in contacts:
                contact.account_id = self.current_user.id

        self.session.commit()
        self.clear_current_user()
        return self.send_success()
Exemple #5
0
 def modify_phone(self):
     """ 修改手机号
     """
     phone = self.args["phone"]
     code = self.args["code"]
     session = self.session
     current_user_id = self.current_user.id
     AccountInfo = models.Accountinfo
     check_msg_res = check_msg_token(phone, code, use="bind")
     if not check_msg_res:
         return self.send_fail("验证码过期或者不正确")
     account_info=session.query(AccountInfo)\
                         .filter_by(id=current_user_id)\
                         .first()
     account_info.phone = phone
     session.commit()
     return self.send_success()
Exemple #6
0
    def login_by_phone_code(self):
        """
        手机号+验证码登录,已注册用户直接登录,未注册用户生成新账号并登录
            phone:手机号
            code:验证码
        """
        phone = self.args["phone"].strip()
        code = self.args["code"].strip()

        if len(phone) != 11:
            return self.send_fail("请填写正确的手机号")

        check_msg_res = check_msg_token(phone, code, use="login")
        if not options.debug and not check_msg_res:
            return self.send_fail("验证码错误或已失效")

        # 登录
        success, user_or_msg = AuthFunc.login_by_phone_code(
            self.session, phone)
        if not success:
            return self.send_fail(user_or_msg)

        # 设置cookie
        self.set_current_user(user_or_msg)

        # 返回微信绑定状态,三者缺一要求重新绑定
        if user_or_msg.wx_unionid and user_or_msg.nickname and user_or_msg.headimgurl:
            wx_bind = True
        else:
            wx_bind = False

        # 更新门店联系人 ID
        contacts = self.session.query(models.ShopContact) \
            .filter(models.ShopContact.phone == phone) \
            .all()
        if contacts:
            for contact in contacts:
                contact.account_id = user_or_msg.id
            self.session.commit()

        return self.send_success(wx_bind=wx_bind)
Exemple #7
0
    def login_by_phone_code(self):
        """手机号+验证码登录,已注册用户直接登录,未注册用户生成新账号并登录
            phone:手机号
            code:验证码
        """
        phone = self.args["phone"]
        code = self.args["code"]
        session = self.session
        Accountinfo = models.Accountinfo

        # 用于app审核
        if phone == "18299999999" and code == "9823":
            phone = "13125182048"
        else:
            check_msg_res = check_msg_token(phone, code, use="login")
            if not check_msg_res:
                return self.send_fail("验证码过期或者不正确")

        try:
            account = session.query(Accountinfo).filter_by(phone=phone).one()
        except NoResultFound:
            account = None

        if not account:
            account = Accountinfo.register_with_phone(session, phone)
            #每当有一个新用户注册的时候,就要对应的增加录入设置的信息
            Accountinfo.init_recorder_settings(session, account.id)
            temp_name = Accountinfo.create_temp_name()
            temp_name = "用户{}".format(temp_name)
            account.nickname = temp_name
            account.realname = temp_name

        session.commit()

        bind_wx = True if account.wx_unionid else False
        self.set_current_user(account, domain=ROOT_HOST_NAME)
        self.which_staff_belong("post", account)
Exemple #8
0
    def login_bind_phone(self):
        """微信登录后进行手机绑定
            phone:手机号
            code:验证码
            name:真实姓名
        """
        filter_emoji = Emoji.filter_emoji
        code = self.args["code"]
        phone = filter_emoji(self.args["phone"].strip())
        name = filter_emoji(self.args.get("name", "").strip())
        current_user = self.current_user
        Accountinfo = models.Accountinfo
        if not current_user:
            return self.send_fail("请先使用微信登录")
        session = self.session
        if current_user.phone:
            return self.send_fail("您已绑定手机号,请前往个人中心进行修改")
        if current_user.phone == phone:
            return self.send_fail("您已绑定该手机号")
        if not current_user.wx_unionid:
            return self.send_fail("请使用微信登录")
        check_msg_res = check_msg_token(phone, code, use="bind")
        if not check_msg_res:
            return self.send_fail("验证码过期或者不正确")
        exist_account = session.query(Accountinfo).filter_by(
            phone=phone).first()
        if exist_account:
            if exist_account.wx_unionid:
                return self.send_fail("该手机号已绑定其他微信")
            origin_wx_unionid = current_user.wx_unionid
            origin_wx_openid = current_user.wx_openid
            origin_wx_country = current_user.wx_country
            origin_wx_province = current_user.wx_province
            origin_wx_city = current_user.wx_city
            origin_nickname = current_user.nickname
            origin_headimgurl = current_user.headimgurl
            origin_sex = current_user.sex
            #清空微信所在账户信息
            current_user.wx_unionid = None
            current_user.wx_openid = None
            session.flush()

            #将微信信息绑定到已有的手机账户上并跳转到已有账户
            exist_account.wx_unionid = origin_wx_unionid
            exist_account.wx_openid = origin_wx_openid
            exist_account.wx_country = origin_wx_country
            exist_account.wx_province = origin_wx_province
            exist_account.wx_city = origin_wx_city
            exist_account.nickname = origin_nickname
            exist_account.realname = name
            exist_account.headimgurl = origin_headimgurl
            exist_account.sex = origin_sex
            session.delete(current_user)
            session.commit()
            self.set_current_user(exist_account, domain=ROOT_HOST_NAME)
            self.which_staff_belong("post", exist_account)
        else:
            current_user.phone = phone
            current_user.realname = name
            #每当有一个新用户注册的时候,就要对应的增加录入设置的信息
            Accountinfo.init_recorder_settings(session, current_user.id)
            session.commit()
            self.which_staff_belong("post", current_user)
Exemple #9
0
    def post(self):
        name = self.args["name"]
        city_code = self.args["city_code"]
        address = self.args["address"]
        phone = self.args["phone"]
        code = self.args["code"]

        province_code = ProvinceCityFunc.city_to_province(city_code)
        if not province_code:
            return self.send_fail("请填写正确的省份")

        if len(phone) != 11:
            return self.send_fail("请填写正确的手机号")

        check_msg_res = check_msg_token(phone, code, use="station_register")
        if not options.debug and not check_msg_res:
            return self.send_fail("验证码过期或者不正确")

        # 检查用于注册的手机号
        success, errmsg = AuthFunc.update_passportinfo(
            self.current_user.passport_id, "phone", phone)
        if not success:
            if errmsg == "NOT EXIST":
                return self.send_fail("请登录后重试")
            elif errmsg == "SAME VALUE":
                pass
            elif errmsg == "ALREADY BIND":
                return self.send_fail("该手机号已被注册")
        self.current_user.phone = phone

        existed_station = self.session.query(models.TransferStation) \
            .join(models.Staff, models.Staff.station_id == models.TransferStation.id) \
            .filter(models.Staff.super_admin_status == 1,
                    models.Staff.status == 0,
                    models.Staff.account_id == self.current_user.id) \
            .first()
        if existed_station:
            return self.send_fail("您已经是 {} 的超级管理员了".format(
                existed_station.name))

        # 添加新中转站
        new_station = models.TransferStation(
            name=name,
            province=province_code,
            city=city_code,
            address=address,
            creator_id=self.current_user.id,
        )
        self.session.add(new_station)
        self.session.flush()

        # 添加默认超管
        super_admin = models.Staff(
            station_id=new_station.id,
            account_id=self.current_user.id,
            super_admin_status=1,
            admin_status=1,
            purchaser_status=0,
            date_onboarding=datetime.date.today(),
        )
        super_admin.set_admin_permissions(None, grant_all=True)
        super_admin.set_purchaser_permissions(None, grant_all=True)
        self.session.add(super_admin)

        # 添加设置项
        config = models.Config(id=new_station.id)
        self.session.add(config)

        self.session.commit()
        self.clear_current_user()
        return self.send_success()
Exemple #10
0
    def post(self):
        #极验验证
        challenge = self.get_argument("geetest_challenge")
        validate = self.get_argument("geetest_validate")
        seccode = self.get_argument("geetest_seccode")
        # print (challenge,)
        # print (seccode)
        # print (validate,'validate')
        if len(challenge) < 2 or len(seccode) < 2 or len(validate) < 2:
            return self.send_fail('请先完成图形验证')
        gt = geetest.geetest(captcha_id, private_key)
        result = gt.geetest_validate(challenge, validate, seccode)
        if not result:
            return self.send_fail('验证码错误')

        try:
            if_admin = self.session.query(models.ShopAdmin).filter_by(
                id=self.current_user.id, role=1).first()
        except:
            if_admin = None
        if if_admin:
            return self.send_fail("您已是卖家")
        #判断申请店铺的微信是否已是某店铺的管理员身份
        # try:
        # 	if_shopadmin = self.session.query(models.HireLink).join(models.ShopStaff,models.HireLink.staff_id == models.ShopStaff.id)\
        # 	.filter(models.HireLink.active==1,models.HireLink.work ==9 ,models.ShopStaff.id == self.current_user.id).first()
        # except:
        # 	if_shopadmin = None
        # try:
        # 	if_shop = self.session.query(models.Shop).filter_by(id = if_admin.shop_id).first()
        # except:
        # 	if_shop = None
        # if if_shopadmin:
        # 	return self.send_fail('该账号已是'+if_shop.shop_name+'的管理员,不能使用该账号申请店铺,若要使用该账号,请退出'+if_shop.shop_name+'管理员身份更换或其它账号')

        if not self.args['phone']:
            return self.send_fail("please input your phone number")
        if not self.args["realname"]:
            return self.send_fail("please input your realname")
        if not check_msg_token(phone=self.args['phone'],
                               code=int(self.args["code"])):
            return self.send_fail(error_text="验证码过期或者不正确")

        if len(self.args["phone"]) > 11:
            return self.send_fail("手机号格式错误")
        if len(self.args["realname"]) > 20:
            return self.send_fail("真实姓名请不要超过20个字")
        if len(self.args["wx_username"]) > 20:
            return self.send_fail("微信号请不要超过20个字")

        if_normal_admin = self.session.query(
            models.ShopAdmin).filter_by(id=self.current_user.id).first()
        # print(if_normal_admin)
        self.current_user.accountinfo.phone = self.args["phone"]
        self.current_user.accountinfo.realname = self.args["realname"]
        self.current_user.accountinfo.wx_username = self.args["wx_username"]
        if if_normal_admin:
            if_normal_admin.role = 1
            if_normal_admin.privileges = -1
        else:
            self.session.add(models.ShopAdmin(id=self.current_user.id))
        self.session.commit()
        return self.send_success()
Exemple #11
0
	def handle_checkcode_regist(self):
		if not check_msg_token(phone = self.args["phone"],code = self.args["code"]):
			return self.send_fail(error_text = "验证码过期或者不正确")
		else:
			return self.send_success()
Exemple #12
0
	def post(self):
		#* todo 检查合法性
		if self._action == "apply":
			account_id = self.current_user.accountinfo.id
			#判断申请店铺的微信是否已是某店铺的管理员身份
			try:
				if_admin = self.session.query(models.HireLink).join(models.ShopStaff,models.HireLink.staff_id == models.ShopStaff.id)\
				.filter(models.HireLink.active==1,models.HireLink.work ==9 ,models.ShopStaff.id == account_id).first()
			except:
				if_admin = None
			try:
				if_shop = self.session.query(models.Shop).filter_by(id = if_admin.shop_id).first()
			except:
				if_shop = None
			if if_admin:
				return self.send_fail('该账号已是'+if_shop.shop_name+'的管理员,不能使用该账号申请店铺,若要使用该账号,请退出'+if_shop.shop_name+'管理员身份更换或其它账号')


			#首个店铺未进行店铺认证不允许再申请店铺
			try:
				shops = self.session.query(models.Shop).filter_by(admin_id=account_id)
			except:
				shops = None

			if shops:
				shop_frist = shops.first()
				if shop_frist:
					if shop_frist.shop_auth==0:
						return self.send_fail("您的第一个店铺还未进行认证,店铺认证后才可申请多个店铺。个人认证可申请5个店铺,企业认证可申请15个店铺。")
					elif shop_frist.shop_auth in [1,4] and shops.count() >= 5:
						return self.send_fail("首个店铺为个人认证最多只可申请5个店铺")
					elif shop_frist.shop_auth in [2,3] and shops.count() >= 15:
						return self.send_fail("首个店铺为企业认证最多只可申请15个店铺")

			if not check_msg_token(phone=self.args['shop_phone'], code=self.args["code"]):
				# print('check_msg_token' + self.current_user.accountinfo.wx_unionid)
				return self.send_fail(error_text="验证码过期或者不正确")  #
			# 这种检查方式效率比较低
			if len(self.current_user.shops) >= self.MAX_APPLY_COUNT:
				return self.send_fail(error_text="您申请的店铺数量超过限制!最多能申请{0}家".format(self.MAX_APPLY_COUNT))
			self.session.add(models.ShopTemp(admin_id=self.current_user.id,
			  shop_name=self.args["shop_name"],
			  shop_province=self.args["shop_province"],
			  shop_city = self.args["shop_city"],
			  shop_address_detail=self.args["shop_address_detail"],
			  shop_phone =self.args["shop_phone"],
			  have_offline_entity=self.args["have_offline_entity"],
			  shop_service_area=self.args["shop_service_area"],
			  shop_intro=self.args["shop_intro"],
			  lat=self.args["lat"],
			  lon=self.args["lon"]),
			)

			self.current_user.accountinfo.realname = self.args["realname"]
			self.current_user.accountinfo.wx_username = self.args["wx_username"]
			self.session.commit()
			return self.send_success()

		elif self._action == "reApply":
			if not "shop_id" in self.args:
				return  self.send_error(404)
			shop_id = self.args["shop_id"]
			try:
				shop_temp = self.session.query(models.ShopTemp).filter_by(id=shop_id).one()
			except:
				shop_temp = None
			if not shop_temp:
				return self.send_error(404)
			shop_temp.update(session=self.session, shop_name=self.args["shop_name"],
						shop_province=self.args["shop_province"],
						shop_city=self.args["shop_city"],
						shop_address_detail=self.args["shop_address_detail"],
						have_offline_entity=self.args["have_offline_entity"],
						shop_service_area=self.args["shop_service_area"],
						shop_intro=self.args["shop_intro"],
						shop_phone = self.args["shop_phone"],
						shop_status = models.SHOP_STATUS.APPLYING)
			return self.send_success()