コード例 #1
0
	def login(data):
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				login_query = "SELECT users.otp, users.user_id, users.first_name, users.last_name, users.color_theme, users.image\
				FROM users WHERE users.email LIKE %s"
				cur.execute(login_query, (data['email'], ))
				user = cur.fetchone()
				response = User()
				if(user[0]==data['otp']):
					response.email= data['email']
					response.user_id = user[1]
					response.first_name = user[2]
					response.last_name = user[3]
					response.color_theme = user[4]
					response.image = user[5]
					get_role_query = "SELECT user_role.role_id FROM user_role WHERE user_role.user_id = %s"
					cur.execute(get_role_query, (user[1],))
					response.role_id = cur.fetchone()[0]
					response.token = (Jwt.encode_auth_token(user_id=user[1], role_id=response.role_id)).decode()
					cur.close()
					conn.close()
					return response
				else:
					return False
			else:
				return False
		except Exception as e:
			raise e
コード例 #2
0
	def login(self, data):
		try:
			mongo_config = MongoConfig()
			collection = mongo_config.db()
			if(collection):
				user_obj = User()
				search_user = {'email': data['email']}
				user = collection.find(search_user)
				crypto = Crypto()
				if(user):
					if(crypto.verify_decrypted_string(data['password'], user[0]['password'])):
						user_obj.first_name = user[0]['firstName']
						#user_obj.last_name = user[0]['lastName']
						user_obj.user_id = str(user[0]['_id'])
						user_obj.token = Jwt.encode_auth_token(user_id=user[0]['_id']).decode()
						return user_obj
					else:
						return "Invalid Credentials"
				else:
					return "User not available"
			else:
				return "Unable to connect to database"
		except IndexError as IE:
			return "User not available"
		except Exception as e:
			raise e
コード例 #3
0
	def check_fb_user_existence(email):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				select_query = "SELECT user_id, first_name, color_theme, image FROM users WHERE email LIKE %s AND type = %s"
				cur.execute(select_query, (email, 'fb', ));
				obj = cur.fetchone()
				response = User()
				if(obj):
					get_role = "SELECT role_id FROM user_role WHERE user_id = %s"
					cur.execute(get_role, (obj[0],));
					role = cur.fetchone()
					response.email= email
					response.user_id = obj[0]
					response.role_id = role[0]
					response.first_name = obj[1]
					response.color_theme = obj[2]
					response.image = obj[3]
					response.token = (Jwt.encode_auth_token(user_id=obj[0], role_id=response.role_id)).decode()
					cur.close()
					conn.close()
					return response
				else:
					cur.close()
					conn.close()
					return False
			else:
				return False
		except Exception as e:
			return  e