Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
assetmanagerLogin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arun.uday
assetmanagerLogin
Commits
2b256755
Commit
2b256755
authored
Mar 15, 2023
by
arun.uday
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated including new file
parent
5c699869
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
152 additions
and
44 deletions
+152
-44
.env
.env
+1
-0
requirements.txt
requirements.txt
+2
-1
scripts/__init__.py
scripts/__init__.py
+0
-0
scripts/config/__init__.py
scripts/config/__init__.py
+1
-4
scripts/constants/api.py
scripts/constants/api.py
+7
-2
scripts/constants/db_constants.py
scripts/constants/db_constants.py
+4
-0
scripts/core/handlers/loginmanager.py
scripts/core/handlers/loginmanager.py
+30
-8
scripts/core/handlers/validation_login.py
scripts/core/handlers/validation_login.py
+15
-0
scripts/database/mongo/__init__.py
scripts/database/mongo/__init__.py
+8
-0
scripts/database/mongo/mongo_login.py
scripts/database/mongo/mongo_login.py
+33
-0
scripts/services/__init__.py
scripts/services/__init__.py
+3
-4
scripts/services/v1/__init__.py
scripts/services/v1/__init__.py
+6
-0
scripts/services/v1/iot_manager_services.py
scripts/services/v1/iot_manager_services.py
+20
-0
scripts/utils/mongo_tools/mongo_sync.py
scripts/utils/mongo_tools/mongo_sync.py
+22
-25
No files found.
.env
View file @
2b256755
MONGO_URI=mongodb://localhost:27017
MONGO_URI=mongodb://localhost:27017
DB_NAME=userDB
SERVICE_HOST=0.0.0.0
SERVICE_HOST=0.0.0.0
SERVICE_PORT=8671
SERVICE_PORT=8671
requirements.txt
View file @
2b256755
...
@@ -3,4 +3,5 @@ python-dotenv~=1.0.0
...
@@ -3,4 +3,5 @@ python-dotenv~=1.0.0
pydantic
~=1.10.6
pydantic
~=1.10.6
fastapi
~=0.94.1
fastapi
~=0.94.1
passlib
~=1.7.4
passlib
~=1.7.4
pymongo
~=4.3.3
pymongo
~=4.3.3
\ No newline at end of file
bcrypt
~=4.0.1
\ No newline at end of file
scripts/__init__.py
0 → 100644
View file @
2b256755
scripts/config/__init__.py
View file @
2b256755
...
@@ -16,16 +16,13 @@ class _Services(BaseSettings):
...
@@ -16,16 +16,13 @@ class _Services(BaseSettings):
CORS_ALLOW_CREDENTIALS
:
bool
=
True
CORS_ALLOW_CREDENTIALS
:
bool
=
True
CORS_ALLOW_METHODS
:
list
[
str
]
=
[
"GET"
,
"POST"
,
"DELETE"
,
"PUT"
]
CORS_ALLOW_METHODS
:
list
[
str
]
=
[
"GET"
,
"POST"
,
"DELETE"
,
"PUT"
]
CORS_ALLOW_HEADERS
:
list
[
str
]
=
[
"*"
]
CORS_ALLOW_HEADERS
:
list
[
str
]
=
[
"*"
]
SELF_PROXY
:
Optional
[
str
]
=
Field
(
None
,
env
=
"DIGITAL_SIGNATURE_PROXY"
)
LOG_LEVEL
:
Literal
[
"INFO"
,
"DEBUG"
,
"ERROR"
,
"QTRACE"
]
=
"INFO"
LOG_LEVEL
:
Literal
[
"INFO"
,
"DEBUG"
,
"ERROR"
,
"QTRACE"
]
=
"INFO"
ENABLE_FILE_LOGGING
:
bool
=
False
ENABLE_FILE_LOGGING
:
bool
=
False
SECRET_KEY
=
"a8f3e3ed5f0dd73bca711df807b1141e15a499bc5e555d44fcab501c4147ee23"
ALGORITHM
=
"HS256"
ACCESS_TOKEN_EXPIRES_MINUTES
=
800
class
_Databases
(
BaseSettings
):
class
_Databases
(
BaseSettings
):
MONGO_URI
:
str
MONGO_URI
:
str
DB_NAME
:
str
Services
=
_Services
()
Services
=
_Services
()
...
...
scripts/constants/api.py
View file @
2b256755
class
ApiEndPoints
:
class
ApiEndPoints
:
# version
version
=
"/v1"
version
=
"/v1"
asset_manager_login
=
"/login"
asset_manager_submit
=
"/nor-login"
# common
asset_manager_submit
:
str
=
"/submit"
# login-management
asset_manager_login
:
str
=
"/login"
scripts/constants/db_constants.py
0 → 100644
View file @
2b256755
class
DatabaseConstants
:
collection_user_details
=
"userDetails"
collection_user_roles
=
"userRoles"
collection_user_devices
=
"userDevices"
scripts/core/handlers/loginmanager.py
View file @
2b256755
from
fastapi.security
import
OAuth2PasswordBearer
import
bcrypt
from
passlib.context
import
CryptContext
from
scripts.database.mongo.mongo_login
import
MongoUser
from
scripts.logging.logger
import
logger
class
LoginManager
:
class
LoginManager
:
def
__init__
(
self
):
@
staticmethod
self
.
pwd_context
=
CryptContext
(
schemes
=
[
"bcrypt"
],
deprecated
=
"auto"
)
def
verify_password
(
encrypted_password
,
password
):
self
.
oauth2_scheme
=
OAuth2PasswordBearer
(
tokenUrl
=
"token"
)
pwd
=
password
decoded_pwd
=
pwd
.
encode
(
'utf-8'
)
print
(
encrypted_password
,
password
)
if
bcrypt
.
checkpw
(
encrypted_password
,
decoded_pwd
):
return
True
return
False
@
staticmethod
def
hashed_password
(
password
):
try
:
pwd
=
password
encode_pwd
=
pwd
.
encode
(
'utf-8'
)
# Generate salt
salted
=
bcrypt
.
gensalt
()
# Hash password
pwd_hash
=
bcrypt
.
hashpw
(
encode_pwd
,
salted
)
def
hashed_password
(
self
,
password
):
return
pwd_hash
return
self
.
pwd_context
.
hash
(
password
)
except
Exception
as
e
:
logger
.
exception
(
e
)
# def get_data(self, username, hashed):
@
staticmethod
def
get_data
(
username
):
data
=
MongoUser
()
.
fetch_user_details
(
username
)
return
data
scripts/core/handlers/validation_login.py
View file @
2b256755
from
scripts.logging.logger
import
logger
class
ValidateUser
:
@
staticmethod
def
valid_user
(
db_data
,
username
,
password
):
try
:
if
db_data
[
"email"
]
!=
username
:
return
False
if
db_data
[
"password"
]
!=
password
:
print
(
db_data
[
"password"
],
password
)
return
False
return
True
except
Exception
as
e
:
logger
.
exception
(
e
)
scripts/database/mongo/__init__.py
0 → 100644
View file @
2b256755
from
scripts.config
import
Databases
from
scripts.utils.mongo_utils
import
MongoConnect
mongo_obj
=
MongoConnect
(
uri
=
Databases
.
MONGO_URI
)
mongo_client
=
mongo_obj
()
CollectionBaseClass
=
mongo_obj
.
get_base_class
()
scripts/database/mongo/mongo_login.py
0 → 100644
View file @
2b256755
from
scripts.config
import
Databases
from
scripts.constants.db_constants
import
DatabaseConstants
from
scripts.database.mongo
import
CollectionBaseClass
,
mongo_client
collection_name
=
DatabaseConstants
.
collection_user_details
class
UserDetailsKeys
:
KEY_NAME
=
"name"
KEY_EMAIL
=
"email"
KEY_PASSWORD
=
"password"
KEY_USER_ROLE
=
"user_role"
KEY_IS_ALIVE
=
"is_alive"
KEY_CREATED_AT
=
"created_at"
KEY_UPDATED_AT
=
"updated_at"
class
MongoUser
(
CollectionBaseClass
):
key_name
=
UserDetailsKeys
.
KEY_NAME
key_email
=
UserDetailsKeys
.
KEY_EMAIL
key_password
=
UserDetailsKeys
.
KEY_PASSWORD
key_user_role
=
UserDetailsKeys
.
KEY_USER_ROLE
key_is_alive
=
UserDetailsKeys
.
KEY_IS_ALIVE
key_created_at
=
UserDetailsKeys
.
KEY_CREATED_AT
key_updated_at
=
UserDetailsKeys
.
KEY_UPDATED_AT
def
__init__
(
self
):
super
()
.
__init__
(
mongo_client
,
Databases
.
DB_NAME
,
collection_name
)
def
fetch_user_details
(
self
,
email
):
if
user
:
=
self
.
find_one
(
query
=
{
self
.
key_email
:
email
}):
return
user
return
None
scripts/services/__init__.py
View file @
2b256755
from
fastapi
import
FastAPI
from
fastapi
import
FastAPI
from
scripts.constants.api
import
ApiEndPoints
from
scripts.services
import
v1
from
scripts.services
import
iot_manager_services
router
=
FastAPI
(
prefix
=
ApiEndPoints
.
version
)
router
=
FastAPI
()
router
.
include_router
(
iot_manager_services
.
router
)
router
.
include_router
(
v1
.
router
)
scripts/services/v1/__init__.py
0 → 100644
View file @
2b256755
from
fastapi
import
APIRouter
from
scripts.constants.api
import
ApiEndPoints
from
scripts.services.v1
import
iot_manager_services
router
=
APIRouter
(
prefix
=
ApiEndPoints
.
asset_manager_login
)
router
.
include_router
(
iot_manager_services
.
router
)
scripts/services/iot_manager_services.py
→
scripts/services/
v1/
iot_manager_services.py
View file @
2b256755
...
@@ -2,18 +2,19 @@ from fastapi import APIRouter
...
@@ -2,18 +2,19 @@ from fastapi import APIRouter
from
scripts.constants.api
import
ApiEndPoints
from
scripts.constants.api
import
ApiEndPoints
from
scripts.core.handlers.loginmanager
import
LoginManager
from
scripts.core.handlers.loginmanager
import
LoginManager
from
scripts.logging.logger
import
logger
from
scripts.schemas.login_schema
import
NormalLogin
from
scripts.schemas.login_schema
import
NormalLogin
router
=
APIRouter
(
prefix
=
ApiEndPoints
.
version
)
router
=
APIRouter
(
prefix
=
ApiEndPoints
.
version
)
@
router
.
post
(
ApiEndPoints
.
asset_manager_login
)
def
login_default
(
login_data
:
NormalLogin
):
obj_login_manager
=
LoginManager
()
password_hashed
=
obj_login_manager
.
hashed_password
(
login_data
.
password
)
return
password_hashed
@
router
.
post
(
ApiEndPoints
.
asset_manager_submit
)
@
router
.
post
(
ApiEndPoints
.
asset_manager_submit
)
def
submit_login_details
():
def
login_default
(
login_data
:
NormalLogin
):
return
{
"message"
:
"its working"
}
try
:
obj_login_manager
=
LoginManager
()
password_hashed
=
obj_login_manager
.
hashed_password
(
login_data
.
password
)
cursor_user_data
=
obj_login_manager
.
get_data
(
login_data
.
username
)
user_exists
=
obj_login_manager
.
verify_password
(
password_hashed
,
cursor_user_data
[
"password"
])
return
user_exists
except
Exception
as
e
:
logger
.
exception
(
e
)
scripts/utils/mongo_tools/mongo_sync.py
View file @
2b256755
from
__future__
import
annotations
import
logging
import
logging
from
typing
import
Any
,
Dict
,
List
,
Mapping
,
Optional
,
Sequence
,
Tuple
,
Union
from
typing
import
Any
,
Dict
,
List
,
Mapping
,
Optional
,
Sequence
,
Tuple
,
Union
...
@@ -11,22 +13,17 @@ from pymongo.results import (
...
@@ -11,22 +13,17 @@ from pymongo.results import (
UpdateResult
,
UpdateResult
,
)
)
from
scripts.utils.db_name_util
import
get_db_name
class
MongoCollectionBaseClass
:
class
MongoCollectionBaseClass
:
def
__init__
(
def
__init__
(
self
,
self
,
mongo_client
:
MongoClient
,
mongo_client
:
MongoClient
,
database
:
str
,
database
:
str
,
collection
:
str
,
collection
:
str
,
project_id
:
Optional
[
str
],
)
->
None
:
)
->
None
:
self
.
client
=
mongo_client
self
.
client
=
mongo_client
self
.
database
=
database
self
.
database
=
database
self
.
collection
=
collection
self
.
collection
=
collection
if
project_id
:
self
.
database
=
get_db_name
(
project_id
=
project_id
,
database
=
self
.
database
)
def
__repr__
(
self
)
->
str
:
def
__repr__
(
self
)
->
str
:
return
f
"{self.__class__.__name__}(database={self.database}, collection={self.collection})"
return
f
"{self.__class__.__name__}(database={self.database}, collection={self.collection})"
...
@@ -64,14 +61,14 @@ class MongoCollectionBaseClass:
...
@@ -64,14 +61,14 @@ class MongoCollectionBaseClass:
raise
raise
def
find
(
def
find
(
self
,
self
,
query
:
dict
,
query
:
dict
,
filter_dict
:
Optional
[
dict
]
=
None
,
filter_dict
:
Optional
[
dict
]
=
None
,
sort
:
Union
[
sort
:
Union
[
None
,
str
,
Sequence
[
Tuple
[
str
,
Union
[
int
,
str
,
Mapping
[
str
,
Any
]]]]
None
,
str
,
Sequence
[
Tuple
[
str
,
Union
[
int
,
str
,
Mapping
[
str
,
Any
]]]]
]
=
None
,
]
=
None
,
skip
:
int
=
0
,
skip
:
int
=
0
,
limit
:
Optional
[
int
]
=
None
,
limit
:
Optional
[
int
]
=
None
,
)
->
Cursor
:
)
->
Cursor
:
"""
"""
The function is used to query documents from a given collection in a Mongo Database
The function is used to query documents from a given collection in a Mongo Database
...
@@ -126,11 +123,11 @@ class MongoCollectionBaseClass:
...
@@ -126,11 +123,11 @@ class MongoCollectionBaseClass:
raise
raise
def
update_one
(
def
update_one
(
self
,
self
,
query
:
dict
,
query
:
dict
,
data
:
dict
,
data
:
dict
,
upsert
:
bool
=
False
,
upsert
:
bool
=
False
,
strategy
:
str
=
"$set"
,
strategy
:
str
=
"$set"
,
)
->
UpdateResult
:
)
->
UpdateResult
:
"""
"""
...
@@ -151,7 +148,7 @@ class MongoCollectionBaseClass:
...
@@ -151,7 +148,7 @@ class MongoCollectionBaseClass:
raise
raise
def
update_many
(
def
update_many
(
self
,
query
:
dict
,
data
:
dict
,
upsert
:
bool
=
False
self
,
query
:
dict
,
data
:
dict
,
upsert
:
bool
=
False
)
->
UpdateResult
:
)
->
UpdateResult
:
"""
"""
...
@@ -217,8 +214,8 @@ class MongoCollectionBaseClass:
...
@@ -217,8 +214,8 @@ class MongoCollectionBaseClass:
raise
raise
def
aggregate
(
def
aggregate
(
self
,
self
,
pipelines
:
list
,
pipelines
:
list
,
)
->
CommandCursor
:
)
->
CommandCursor
:
try
:
try
:
database_name
=
self
.
database
database_name
=
self
.
database
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment