Exemple #1
0
def login_check(request):
    username = request.POST.get('username')
    password = request.POST.get('password')
    remember = request.POST.get('remember')

    if not all([username, password, remember]):
        return JsonResponse({'res': 2})
    passport = Passport.object.get_passport(user_name=username,
                                            user_pwd=get_hash(password))
    print(username, get_hash(password), passport)
    if passport:
        print('22222')
        next_url = request.session.get('url_path', reverse('book:index'))
        print('33333')
        jres = JsonResponse({'res': 1, 'next_url': next_url})

        if remember == 'true':
            print('44444')
            jres.set_cookie('username', username, max_age=7 * 24 * 3600)
        else:
            print('55555')
            jres.delete_cookie('username')
        request.session['islogin'] = True
        request.session['username'] = username
        request.session['passport_id'] = passport.id
        print('66666')
        return jres
    else:
        return JsonResponse({'res': 0})
Exemple #2
0
 def add_one_passport(self, username, password, email):
     """添加一个用户注册信息"""
     obj = self.create_one_object(username=username,
                                  password=get_hash(password),
                                  email=email)
     # 返回obj
     return obj
Exemple #3
0
 def get_one_passport(self, username, password=None):
     """判断用户是否存在/判断用户名和密码是否正确"""
     if password:
         obj = self.get_one_object(username=username, password=get_hash(password))
     else:
         obj = self.get_one_object(username=username)
     return obj
Exemple #4
0
    def add_one_passport(self, username, password, email):
        """添加一个账户信息"""
        passport = self.create(username=username,
                               password=get_hash(password),
                               email=email)

        return passport
	def get_one_passport(self, username, password):
		# 根据账号密码查找信息
		try:
			passport = self.get(username=username, password=get_hash(password))
		except self.model.DoesNotExist:
			passport = None
		return passport
Exemple #6
0
	def add_one_passport(self, username, password, email):
		try:
			passport = self.create(username=username, password=get_hash(password), email=email)
		except self.model.DoesNotExist:  # 指定异常捕获
			# 账户不存在-->self.model-->model当前查询的模型,
			passport = None
		return passport
Exemple #7
0
 def add_one_passport(self, username, password, email):
     passport = self.model()
     passport.username = username
     passport.password = get_hash(password)
     passport.email = email
     passport.save()
     return passport
Exemple #8
0
 def add_one_passport(self, username, password, email):
     '''添加一个账户信息'''
     passport = self.create(username=username,
                            password=get_hash(password),
                            email=email)
     # 3.返回passport
     return passport
Exemple #9
0
 def get_one_passport(self, username, password):
     try:
         passport = self.get(username=username, password=get_hash(password))
         print('passport', passport)
     except self.model.DoesNotExist:
         passport = None
     return passport
Exemple #10
0
    def get_one_passport(self,username,password=None):

        if password is None:
            passport = self.get_one_object(username=username)
        else:
            passport = self.get_one_object(username=username, password=get_hash(password))
        return passport
Exemple #11
0
 def add_one_passport(self, username, password, email):
     '''添加一个注册用户信息'''
     obj = self.create_one_object(username=username,
                                  password=get_hash(password),
                                  email=email)
     # 返回对象
     return obj
Exemple #12
0
 def add_one_passport(self, username, password, email):
     # 利用抽象的模型管理器基类的方法保存数据
     obj = self.create_one_object(username=username,
                                  password=get_hash(password),
                                  email=email)
     # 返回对象
     return obj
Exemple #13
0
 def add_one_passport(self, username, password, email):
     '''
     添加一个用户注册信息
     '''
     passport = self.create_one_object(username=username,
                                       password=get_hash(password),
                                       email=email)
     return passport
Exemple #14
0
 def update_one_object(self, username, password, name, phone, detail):
     '''更新一条用户的基本信息'''
     obj = self.get(username=username)
     obj.password = get_hash(password)
     obj.name = name
     obj.phone = phone
     obj.detail = detail
     obj.save()
Exemple #15
0
 def get_one_passport(self, username, password=None):
     """判断用户是否存在/判断用户名和密码是否正确"""
     if password:
         obj = self.get_one_object(username=username,
                                   password=get_hash(password))
     else:
         obj = self.get_one_object(username=username)
     return obj
Exemple #16
0
 def get_one_passport(self, username, password):
     '''根据用户名密码查找账户的信息'''
     try:
         passport = self.get(username=username, password=get_hash(password))
     except self.model.DoesNotExist:
         # 账户不存在
         passport = None
     return passport
Exemple #17
0
 def add_one_passport(self, username, password, email):
     #添加一个账户信息
     #get_hash()这里是获取到加密后的密码
     passport = self.create(username=username,
                            password=get_hash(password),
                            email=email)
     #返回passport
     return passport
Exemple #18
0
    def add_on_passport1(self, username,password,email):

        model_class = self.model
        passport = model_class()
        passport.username = username
        passport.password = get_hash(password)
        passport.email = email
        passport.save()
        return passport
Exemple #19
0
	def get_one_passport(self, username, password):
		try:
			passport = self.get(username=username, password=get_hash(password))
		except self.model.DoesNotExist:  # 指定异常捕获
			# 账户不存在-->self.model-->model当前查询的模型,
			passport = None
		# except Exception as e:
		# 	# 只要抛出异常就被捕获
		# 	print(e)
		return passport
Exemple #20
0
 def add_one_passport(self, username, password, email):
     '''添加一个账户信息'''
     try:
         passport = self.create(username=username,
                                password=get_hash(password),
                                email=email)
     except Exception as e:
         print('e: ', e)
     # 3.返回passport
     return passport
Exemple #21
0
 def get_one_passport(self, username, password=None):
     """根据用户名查询账户信息"""
     if password is None:
         # 根据用户名查找账户信息
         obj = self.get_one_object(username=username)
     else:
         # 根据用户名和密码查找账户信息
         obj = self.get_one_object(username=username,
                                   password=get_hash(password))
     return obj
Exemple #22
0
 def add_one_passport(self, username, password, email):
     # 插入数据的passport的值为什么,需要返回的对象是什么,有什么方法????????????????
     try:
         passport = self.create(username=username,
                                password=get_hash(password),
                                email=email)
     except Exception as e:
         print('错误原因', e)
         passport = None
     return passport
Exemple #23
0
 def find_user(self,username, password):
     '''根据用户的信息进行查找用户'''
     try:
         passport = self.get(username=username, password=get_hash(password))
     except self.model.DoesNotExist:
         # 账户不存在
         print("=======")
         passport = None
     # 返回当前的信息
     return passport
Exemple #24
0
 def get_one_passport(self, username, password=None):
     """根据用户名查询账户信息"""
     try:
         if password is None:
             # 根据用户名查找账户信息
             obj = self.get(user_name=username)
         else:
             obj = self.get(user_name=username, password=get_hash(password))
     except self.model.DoesNotExist:
         # 查不到
         obj = None
     return obj
Exemple #25
0
 def get_one_passport(self, username=None, password=None, email=None):
     try:
         if email is not None:
             passport = self.get(email=email)
         elif password is None:
             passport = self.get(username=username)
         else:
             passport = self.get(username=username,
                                 password=get_hash(password))
     except:
         passport = None
     return passport
Exemple #26
0
 def add_one_passport(self, username, password, email):
     """ # self.model可获取类名Passport
     obj = self.model()  # 创建对象
     obj.username = username
     obj.password = password
     obj.email = email
     obj.save()"""
     # 可直接调用父类的create方法
     obj = self.create(username=username,
                       password=get_hash(password),
                       email=email)
     return obj
Exemple #27
0
 def add_one_passport(self, username, password, email):
     '''添加一个注册用户信息'''
     # 1.获取self对象所在的模型类
     model_class = self.model
     # 2.创建一个model_class类对象
     obj = model_class(username=username,
                       password=get_hash(password),
                       email=email)
     # 3.保存进数据库
     obj.save()
     # 4.返回对象
     return obj
Exemple #28
0
 def get_one_passport(self, username, password):
     """
     根据用户名密码查找账户的信息
     :param username:
     :param password:
     :return: passport:
     """
     try:
         passport = self.get(username=username, password=get_hash(password))
     except self.model.DoesNotExist:
         passport = None
     return passport
Exemple #29
0
 def add_one_passport(self, username, password, email):
     """添加一个用户注册信息"""
     # 1.获取self所在的模型类
     model_class = self.model
     # 2.创建一个model_class模型类对象
     obj = model_class(user_name=username,
                       password=get_hash(password),
                       email=email)
     # obj = self.model(user_name=username,passport=passport,email=email)
     # 3.保存进数据库
     obj.save()
     # 4.返回obj
     return obj
Exemple #30
0
 def get_one_passport(self, username, password=None):
     # 根据用户名查找账户信息
     try:
         if password is None:
             # 根据用户名查找账户
             obj = self.get_one_object(username=username)
         else:
             # 根据用户名和密码查找账户信息,密码要使用哈希值
             obj = self.get_one_object(password=get_hash(password),
                                       username=username)
     except self.model.DoesNotExist:
         obj = None
     return obj
Exemple #31
0
 def get_one_passport(self, username, password=None):
     '''
     根据用户名和密码查询账户信息
     '''
     '''
     if password:
         obj = self.get_one_object(username=username,password=get_hash(password))
     else:
         obj = self.get_one_object(username=username)
     '''
     if password is None:
         obj = self.get_one_object(username=username)
     else:
         obj = self.get_one_object(username=username,
                                   password=get_hash(password))
     return obj
Exemple #32
0
 def add_one_passport(self, username, password, email):
     """添加一个用户注册信息"""
     self.add_one_object(username=username, password=get_hash(password), email=email)
Exemple #33
0
 def add_one_passport(self,username,password,email):
     '''添加一个注册用户到数据库'''
     obj = self.add_one_object(username=username,
                               password=get_hash(password),
                               email=email)
     return obj