Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
IDATT2900-072
Manage
Activity
Members
Labels
Plan
Issues
6
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mattias Agentoft Eggen
IDATT2900-072
Commits
7cca7d74
Commit
7cca7d74
authored
2 years ago
by
magnus2142
Browse files
Options
Downloads
Patches
Plain Diff
fixed login bug, and added logout
parent
d816e9e7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bbcli/__version__.py
+1
-1
1 addition, 1 deletion
bbcli/__version__.py
bbcli/cli.py
+53
-25
53 additions, 25 deletions
bbcli/cli.py
bbcli/services/authorization_service.py
+0
-3
0 additions, 3 deletions
bbcli/services/authorization_service.py
bbcli/utils/utils.py
+16
-3
16 additions, 3 deletions
bbcli/utils/utils.py
with
70 additions
and
32 deletions
bbcli/__version__.py
+
1
−
1
View file @
7cca7d74
VERSION
=
(
0
,
0
,
3
)
VERSION
=
(
0
,
0
,
4
)
PRERELEASE
=
None
# alpha, beta or rc
REVISION
=
None
...
...
This diff is collapsed.
Click to expand it.
bbcli/cli.py
+
53
−
25
View file @
7cca7d74
...
...
@@ -14,18 +14,6 @@ from bbcli.commands.assignments import get_assignments
from
bbcli.services.authorization_service
import
login
import
mmap
load_dotenv
()
cookies
=
{
'
BbRouter
'
:
os
.
getenv
(
"
BB_ROUTER
"
)}
headers
=
{
'
X-Blackboard-XSRF
'
:
os
.
getenv
(
'
XSRF
'
)}
#----- AUTHORIZATION MODULE -----#
# @app.command(name='login', help='Authorize the user.')
def
authorize_user
():
if
cookies
[
'
BbRouter
'
]
==
None
or
check_valid_date
(
cookies
)
==
False
:
login
()
def
initiate_session
():
bb_cookie
=
{
...
...
@@ -40,16 +28,21 @@ def initiate_session():
session
.
headers
.
update
({
'
Content-Type
'
:
'
application/json
'
})
return
session
def
authenticate_user
():
load_dotenv
()
bb_cookie
=
os
.
getenv
(
'
BB_ROUTER
'
)
is_authorized
=
True
if
bb_cookie
!=
None
and
check_valid_date
(
bb_cookie
)
else
False
if
not
is_authorized
:
click
.
echo
(
'
You are not logged in. Executing authorization script...
'
)
login
()
@click.group
()
@click.pass_context
def
entry_point
(
ctx
):
ctx
.
ensure_object
(
dict
)
authorize_user
()
session
=
initiate_session
()
ctx
.
obj
[
'
SESSION
'
]
=
session
# """
...
...
@@ -86,10 +79,32 @@ def entry_point(ctx):
# entry_point.add_command(activate_shell_completion)
"""
COURSE COMMANDS ENTRY POINT
LOGIN AND LOGOUT COMMANDS
"""
@click.command
(
name
=
'
login
'
)
def
authorize_user
():
"""
Authorize user with username and password.
"""
login
()
@click.command
(
name
=
'
logout
'
)
def
logout
():
"""
Logout user.
"""
open
(
f
'
{
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
}
/.env
'
,
'
w
'
).
close
()
click
.
echo
(
'
Sucessfully logged out.
'
)
entry_point
.
add_command
(
authorize_user
)
entry_point
.
add_command
(
logout
)
"""
COURSE COMMANDS ENTRY POINT
"""
@entry_point.group
()
@click.pass_context
...
...
@@ -97,7 +112,10 @@ def courses(ctx):
"""
Commands for listing courses
"""
pass
authenticate_user
()
load_dotenv
()
session
=
initiate_session
()
ctx
.
obj
[
'
SESSION
'
]
=
session
courses
.
add_command
(
list_courses
)
...
...
@@ -114,8 +132,10 @@ def announcements(ctx):
"""
Commands for listing, creating, deleting and updating announcements
"""
pass
authenticate_user
()
load_dotenv
()
session
=
initiate_session
()
ctx
.
obj
[
'
SESSION
'
]
=
session
announcements
.
add_command
(
list_announcements
)
announcements
.
add_command
(
create_announcement
)
...
...
@@ -129,8 +149,10 @@ def assignments(ctx):
"""
Commands for creating, listing and submitting assignments.
"""
pass
authenticate_user
()
load_dotenv
()
session
=
initiate_session
()
ctx
.
obj
[
'
SESSION
'
]
=
session
assignments
.
add_command
(
get_assignments
)
assignments
.
add_command
(
create_assignment
)
...
...
@@ -146,7 +168,10 @@ def contents(ctx):
"""
Commands for listing, creating, deleting, updating and downloading content
"""
pass
authenticate_user
()
load_dotenv
()
session
=
initiate_session
()
ctx
.
obj
[
'
SESSION
'
]
=
session
contents
.
add_command
(
list_contents
)
...
...
@@ -165,7 +190,10 @@ def create(ctx):
"""
Commands for creating different types of content types in blackboard
"""
pass
authenticate_user
()
load_dotenv
()
session
=
initiate_session
()
ctx
.
obj
[
'
SESSION
'
]
=
session
create
.
add_command
(
create_document
)
...
...
This diff is collapsed.
Click to expand it.
bbcli/services/authorization_service.py
+
0
−
3
View file @
7cca7d74
from
urllib
import
request
import
os
from
dotenv
import
load_dotenv
from
bbcli.entities.RequestData
import
RequestData
import
requests
import
json
...
...
@@ -143,7 +142,6 @@ def scrape_microsoft_login_response(response, request_data):
canary
=
script_content
[
'
canary
'
]
auth_methods
=
script_content
[
'
arrUserProofs
'
]
auth_method_id
=
find_default_auth_method
(
auth_methods
)
print
(
auth_method_id
)
if
(
auth_method_id
==
None
):
auth_method_id
=
choose_auth_method
(
auth_methods
)
hpg_request_id
=
response
.
headers
[
'
x-ms-request-id
'
]
...
...
@@ -307,5 +305,4 @@ def write_to_env_data(session):
if
__name__
==
"
__main__
"
:
load_dotenv
()
login
()
This diff is collapsed.
Click to expand it.
bbcli/utils/utils.py
+
16
−
3
View file @
7cca7d74
...
...
@@ -5,6 +5,8 @@ from requests import Session
import
html2text
import
click
from
bbcli.services.authorization_service
import
login
def
check_valid_key
(
obj
,
key
)
->
bool
:
# print("the keys are", obj.keys())
if
key
not
in
obj
.
keys
():
...
...
@@ -24,12 +26,11 @@ def check_response(response) -> bool:
return
True
def
check_valid_date
(
cookie
s
)
->
bool
:
tmp
=
cookie
s
[
'
BbRouter
'
]
def
check_valid_date
(
cookie
)
->
bool
:
tmp
=
cookie
start
=
int
(
tmp
.
find
(
'
expires
'
))
+
len
(
'
expires
'
)
+
1
end
=
int
(
tmp
.
find
(
'
,
'
))
timestmp
=
int
(
tmp
[
start
:
end
])
print
(
timestmp
)
expires
=
datetime
.
fromtimestamp
(
timestmp
)
now
=
datetime
.
now
()
if
expires
>=
now
:
...
...
@@ -78,3 +79,15 @@ def get_download_path(file_name):
return
location
else
:
return
os
.
path
.
join
(
os
.
path
.
expanduser
(
'
~
'
),
f
'
Downloads/
{
file_name
}
'
)
def
authorization_handler
(
func
):
def
inner_function
(
*
args
,
**
kwargs
):
is_authorized
=
True
if
os
.
getenv
(
"
BB_ROUTER
"
)
!=
None
else
False
if
is_authorized
:
func
(
*
args
,
**
kwargs
)
else
:
click
.
echo
(
'
You are not logged in, running login script:
'
)
login
()
click
.
echo
(
'
You can now communicate with Blackboard LMS
'
)
return
inner_function
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment