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
c2ba10de
Commit
c2ba10de
authored
Mar 16, 2023
by
arun.uday
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AssetManager- V1.0 - Not Reviewed
Updates for adding http responses
parent
6e7e6e7c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
17 deletions
+25
-17
app.py
app.py
+4
-1
main.py
main.py
+5
-5
scripts/config/__init__.py
scripts/config/__init__.py
+1
-1
scripts/core/handlers/login_handler.py
scripts/core/handlers/login_handler.py
+2
-3
scripts/errors/__init__.py
scripts/errors/__init__.py
+2
-1
scripts/services/__init__.py
scripts/services/__init__.py
+2
-2
scripts/services/v1/iot_manager_services.py
scripts/services/v1/iot_manager_services.py
+9
-4
No files found.
app.py
View file @
c2ba10de
# iot manager - Arun Uday
# iot manager - Arun Uday
if
__name__
==
"__main__"
:
from
dotenv
import
load_dotenv
load_dotenv
()
import
uvicorn
import
uvicorn
from
scripts.config
import
PROJECT_NAME
,
Services
from
scripts.config
import
PROJECT_NAME
,
Services
...
@@ -11,4 +15,3 @@ if __name__ == "__main__":
...
@@ -11,4 +15,3 @@ if __name__ == "__main__":
uvicorn
.
run
(
"main:app"
,
port
=
int
(
Services
.
PORT
))
uvicorn
.
run
(
"main:app"
,
port
=
int
(
Services
.
PORT
))
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
e
)
logger
.
error
(
e
)
main.py
View file @
c2ba10de
...
@@ -14,26 +14,26 @@ if __name__ == "__main__":
...
@@ -14,26 +14,26 @@ if __name__ == "__main__":
load_dotenv
()
load_dotenv
()
import
uvicorn
from
fastapi
import
FastAPI
from
scripts.services
import
router
from
scripts.services
import
router
from
scripts.config
import
PROJECT_NAME
,
Services
as
ServiceConf
from
scripts.config
import
PROJECT_NAME
,
Services
as
ServiceConf
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.middleware.cors
import
CORSMiddleware
from
scripts.logging.logger
import
logger
from
scripts.logging.logger
import
logger
app
=
FastAPI
()
app
.
include_router
(
router
)
# starting the application
# starting the application
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
try
:
try
:
print
(
"Api for "
+
PROJECT_NAME
)
print
(
"Api for "
+
PROJECT_NAME
)
if
ServiceConf
.
ENABLE_CORS
:
if
ServiceConf
.
ENABLE_CORS
:
router
.
add_middleware
(
app
.
add_middleware
(
CORSMiddleware
,
CORSMiddleware
,
allow_origins
=
ServiceConf
.
CORS_URLS
,
allow_origins
=
ServiceConf
.
CORS_URLS
,
allow_credentials
=
ServiceConf
.
CORS_ALLOW_CREDENTIALS
,
allow_credentials
=
ServiceConf
.
CORS_ALLOW_CREDENTIALS
,
allow_methods
=
ServiceConf
.
CORS_ALLOW_METHODS
,
allow_methods
=
ServiceConf
.
CORS_ALLOW_METHODS
,
allow_headers
=
ServiceConf
.
CORS_ALLOW_HEADERS
,
allow_headers
=
ServiceConf
.
CORS_ALLOW_HEADERS
,
)
)
uvicorn
.
run
(
router
,
port
=
int
(
ServiceConf
.
PORT
))
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
e
)
logger
.
error
(
e
)
scripts/config/__init__.py
View file @
c2ba10de
import
configparser
import
configparser
from
typing
import
Optional
,
Literal
from
typing
import
Literal
from
pydantic
import
BaseSettings
,
Field
from
pydantic
import
BaseSettings
,
Field
...
...
scripts/core/handlers/login_handler.py
View file @
c2ba10de
...
@@ -14,9 +14,9 @@ class LoginHandlers:
...
@@ -14,9 +14,9 @@ class LoginHandlers:
@
staticmethod
@
staticmethod
def
user_data_validation
(
login_data
)
->
dict
|
None
:
def
user_data_validation
(
login_data
)
->
dict
|
None
:
if
login_data
.
username
==
""
or
login_data
.
username
==
"user@example.com"
:
if
login_data
.
username
==
""
or
login_data
.
username
==
"user@example.com"
:
return
{
"message"
:
ErrorMessages
.
ERROR_INVALID_USERNAME
_PASSWORD
,
"data"
:
login_data
.
username
}
return
{
"message"
:
ErrorMessages
.
ERROR_INVALID_USERNAME
,
"data"
:
login_data
.
username
}
if
login_data
.
password
==
""
or
login_data
.
password
==
"string"
:
if
login_data
.
password
==
""
or
login_data
.
password
==
"string"
:
return
{
"message"
:
ErrorMessages
.
ERROR_INVALID_
USERNAME_
PASSWORD
,
"data"
:
login_data
.
password
}
return
{
"message"
:
ErrorMessages
.
ERROR_INVALID_PASSWORD
,
"data"
:
login_data
.
password
}
return
None
return
None
def
db_data_validation
(
self
,
login_data
):
def
db_data_validation
(
self
,
login_data
):
...
@@ -32,4 +32,3 @@ class LoginHandlers:
...
@@ -32,4 +32,3 @@ class LoginHandlers:
return
{
"message"
:
ErrorMessages
.
ERROR_PASSWORD_MISMATCH
,
"data"
:
{
login_data
.
username
,
return
{
"message"
:
ErrorMessages
.
ERROR_PASSWORD_MISMATCH
,
"data"
:
{
login_data
.
username
,
login_data
.
password
}}
login_data
.
password
}}
return
None
return
None
scripts/errors/__init__.py
View file @
c2ba10de
...
@@ -3,6 +3,7 @@ class ErrorMessages:
...
@@ -3,6 +3,7 @@ class ErrorMessages:
OP_FAILED
=
"Operation failed"
OP_FAILED
=
"Operation failed"
# Authorization Errors
# Authorization Errors
ERROR_AUTH_FAILED
=
"Authentication Failed. Please verify token"
ERROR_AUTH_FAILED
=
"Authentication Failed. Please verify token"
ERROR_INVALID_USERNAME_PASSWORD
=
"Invalid Username or Password."
ERROR_INVALID_USERNAME
=
"Invalid Username"
ERROR_INVALID_PASSWORD
=
"Invalid Password"
ERROR_USER_NOT_REGISTERED
=
"Account is not registered in the portal."
ERROR_USER_NOT_REGISTERED
=
"Account is not registered in the portal."
ERROR_PASSWORD_MISMATCH
=
"Passwords Authentication Failed. Please enter the correct password"
ERROR_PASSWORD_MISMATCH
=
"Passwords Authentication Failed. Please enter the correct password"
scripts/services/__init__.py
View file @
c2ba10de
from
fastapi
import
FastAPI
from
fastapi
import
APIRouter
from
scripts.services
import
v1
from
scripts.services
import
v1
router
=
FastAPI
()
router
=
APIRouter
()
router
.
include_router
(
v1
.
router
)
router
.
include_router
(
v1
.
router
)
scripts/services/v1/iot_manager_services.py
View file @
c2ba10de
from
fastapi
import
APIRouter
from
fastapi
import
APIRouter
,
status
from
fastapi.responses
import
JSONResponse
from
scripts.constants.api
import
ApiEndPoints
from
scripts.constants.api
import
ApiEndPoints
from
scripts.core.handlers.login_handler
import
LoginHandlers
from
scripts.core.handlers.login_handler
import
LoginHandlers
...
@@ -15,10 +16,14 @@ def login_default(login_data: NormalLogin):
...
@@ -15,10 +16,14 @@ def login_default(login_data: NormalLogin):
try
:
try
:
response
=
obj_login_handler
.
user_data_validation
(
login_data
)
response
=
obj_login_handler
.
user_data_validation
(
login_data
)
if
response
is
not
None
:
if
response
is
not
None
:
return
DefaultFailureResponse
(
error
=
response
[
"message"
])
return
JSONResponse
(
content
=
DefaultFailureResponse
(
error
=
response
[
"message"
])
.
dict
(),
status_code
=
status
.
HTTP_400_BAD_REQUEST
)
response
=
obj_login_handler
.
db_password_matching
(
login_data
)
response
=
obj_login_handler
.
db_password_matching
(
login_data
)
if
response
is
not
None
:
if
response
is
not
None
:
return
DefaultFailureResponse
(
error
=
response
[
"message"
])
return
JSONResponse
(
content
=
DefaultFailureResponse
(
error
=
response
[
"message"
])
.
dict
(),
return
DefaultResponse
(
message
=
"Login Successful"
,
payload
=
{
"username"
:
login_data
.
username
})
status_code
=
status
.
HTTP_401_UNAUTHORIZED
)
return
JSONResponse
(
content
=
DefaultResponse
(
message
=
"Login Successful"
,
payload
=
{
"username"
:
login_data
.
username
})
.
dict
(),
status_code
=
status
.
HTTP_200_OK
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
exception
(
e
)
logger
.
exception
(
e
)
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