Skip to content

Commit

Permalink
Merge pull request #454 from dzadikdev/bug/hot-fixes
Browse files Browse the repository at this point in the history
Fixes to Linked Objects, Progressive Profile
  • Loading branch information
dzadikdev committed Aug 6, 2021
2 parents 7b6af56 + a3d9ad9 commit 6a701ed
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 14 deletions.
27 changes: 21 additions & 6 deletions GlobalBehaviorandComponents/linkedobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def gbac_linkedobjects():
user_info = get_userinfo()
okta_admin = OktaAdmin(session[SESSION_INSTANCE_SETTINGS_KEY])

schemas = okta_admin.get_user_schemas()
try:
schemas = okta_admin.get_user_schemas()
except Exception:
schemas = ""

nfamily = ""
logger.debug(schemas)
if schemas:
Expand Down Expand Up @@ -62,7 +66,10 @@ def gbac_schemas():
logger.debug("gbac_linkedobjects()")
okta_admin = OktaAdmin(session[SESSION_INSTANCE_SETTINGS_KEY])

schemas = okta_admin.get_user_schemas()
try:
schemas = okta_admin.get_user_schemas()
except Exception:
schemas = ""

return render_template(
"/manageschemas.html",
Expand All @@ -79,8 +86,13 @@ def gbac_newschemas():
logger.debug("gbac_linkedobjects()")
okta_admin = OktaAdmin(session[SESSION_INSTANCE_SETTINGS_KEY])

schemas = okta_admin.get_user_schemas()
message = "Schema Created"
try:
schemas = okta_admin.get_user_schemas()
message = "Schema Created"
except Exception:
schemas = ""
message = "Cannot Create Schema"

return render_template(
"/manageschemascreate.html",
templatename=get_app_vertical(),
Expand All @@ -104,9 +116,12 @@ def gbac_createschemas():
aname = request.form.get('associatedfieldname')
adesc = request.form.get('associateddescription')

okta_admin.create_schema(pname.lower(), ptitle, pdesc, aname.lower(), atitle, adesc)
try:
okta_admin.create_schema(pname.lower(), ptitle, pdesc, aname.lower(), atitle, adesc)
message = "Schema Created"
except Exception:
message = "Cannot Create Schemas. Please contact your adminstrator."

message = "Schema Created"
return redirect(url_for("gbac_lo_bp.gbac_schemas", _external=True, _scheme=session[SESSION_INSTANCE_SETTINGS_KEY]["app_scheme"], message=message))


Expand Down
167 changes: 167 additions & 0 deletions _admin/templates/admin/users_advanced.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{% extends templatename+"/template.html" %}

{% block content %}
<section class="bg-light py-5">
<div class="container">
<div class="d-flex align-items-center mb-5">
<div class="icon-stack icon-stack-lg bg-primary text-white"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-users"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg></div>
<div class="ml-3">
<h2 class="mb-0">Account</h2>
<p class="lead mb-0">Manage Users</p>
</div>
</div>
<div class="card border-bottom">
<div class="card-body">
<div class="separator-2"></div>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th style="text-align:center">User Status</th>
<th style="text-align:center">Temporary MFA Passcode</th>
<th style="text-align:center">User Verification Passcode</th>
</tr>
</thead>
<tbody>
{% for i in userlist %}
<tr>
<td>{{ i['profile']['firstName']}} {{ i['profile']['lastName']}}</td>
<td>{{ i['profile']['email']}}</td>
<td style="text-align:center">{{ i['status'] }}</td>
<td style="text-align:center"><a href="temporarypasscode?user_id={{ i.id}}"><i class="fa fa-clock"></i></a></td>
<td style="text-align:center"><a href="#" onclick="getfactors('{{ i['profile']['firstName']}} {{ i['profile']['lastName']}}','{{ i['id']}}')"><i class="fa fa-key"></i></a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</section>

<!-- Modal -->
<div class="modal fade" id="validateuser" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="ValidateModalLabel">Validate User</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<div id="selectverification" class="form-group">
<label for="factordropdown">Select a Factor: (This sample supports SMS and Email)</label>
<select class="form-control" id="factordropdown">
</select><br>
<button class="btn btn-primary" type="button" onclick="sendFactor()">Send Code</button>
</div>
<div id="inputverification" class="form-group" style="display: none;">
<div class="form-group"><label for="userCode">Enter User's Code</label>
<input class="form-control" id="userCode" type="text"></div>
<div id="apiResponse" class="alert alert-primary" role="alert" style="display: none;">
</div>
<button class="btn btn-primary" type="button" onclick="verifyFactor()">Verify User Code</button>
<button class="btn btn-primary" type="button" onclick="gobackFactor()">Back</button>
</div>
<div id="completeverification" class="form-group" style="display: none;">
User is Verified!
</div>
<input type="hidden" id="userid">

</div>
<div class="modal-footer"><button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>

<script>
function getfactors(name, id) {
$.ajax({
url:'/admin/getfactors?user_id='+id,
type: "GET",
complete: function (response) {
factors = JSON.parse(response.responseText);
dropdownhtml = "";
for (let step = 0; step < factors.length; step++)
{
console.log(factors[step]._links.verify);
if (factors[step].factorType == "sms" && factors[step].status == "ACTIVE")
{
dropdownhtml = dropdownhtml + "<option id='verifysms' value='" + factors[step].id + "'>SMS</option>"
}
else if (factors[step].factorType == "email" && factors[step].status == "ACTIVE")
{
dropdownhtml = dropdownhtml + "<option id='verifyemail' value='" + factors[step].id + "'>Email</option>"
}
}
$("#ValidateModalLabel").html("Validate User: "+ name);
$("#factordropdown").html(dropdownhtml);
$("#userid").val(id);
$("#validateuser").modal("show");
},
error: function () {
alert('No Factors Exist');
},
});
return false;
};

function sendFactor() {
factorid = $("#factordropdown").val();
user_id = $("#userid").val();
$.ajax({
url:'/admin/sendfactor?user_id='+ user_id +"&factor_id=" + factorid,
type: "GET",
complete: function (response) {
myresponse = JSON.parse(response.responseText);
alert("Code Sent");
$("#selectverification").hide();
$("#inputverification").show();
},
error: function () {
myresponse = JSON.parse(response.responseText);
alert(myresponse.errorSummary);
},
});
};

function verifyFactor() {
verifyCode = $("#userCode").val();
factorid = $("#factordropdown").val();
user_id = $("#userid").val();
$.ajax({
url:'/admin/verifyfactor?user_id='+ user_id +"&factor_id=" + factorid + "&code=" + verifyCode,
type: "GET",
complete: function (response) {
myresponse = JSON.parse(response.responseText);
if (myresponse.hasOwnProperty('errorSummary'))
{
$("#apiResponse").html(myresponse.errorSummary);
$("#apiResponse").show();
}
else
{
$("#selectverification").hide();
$("#inputverification").hide();
$("#completeverification").show();
}
},
error: function () {
myresponse = JSON.parse(response.responseText);
alert(myresponse.errorSummary);
},
});
};

function gobackFactor() {
$("#selectverification").show();
$("#inputverification").hide();
$("#completeverification").hide();
};


</script>
{% endblock %}

{% block footer %}
{% endblock %}
1 change: 1 addition & 0 deletions _ecommerce/templates/ecommerce/cart.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h2>{{ config.settings.app_subslogan|safe }}</h2>
</div>
</div>


<script>

$( document ).ready(function() {
Expand Down
18 changes: 10 additions & 8 deletions _ecommerce/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,16 @@ def ecommerce_registration_completion():
user_data = {
"profile": {}
}

if "guestUserId" in request.form:
logger.debug(user_data)
logger.debug(request.form.get('guestUserId'))
guestUserID = request.form.get('guestUserId')
if guestUserID:
user_data = okta_admin.get_user(request.form.get('guestUserId'))

user_data["profile"]["email"] = request.form.get('email')
user_data["profile"]["login"] = request.form.get('email')

logger.debug(user_data)
user_data["profile"]["firstName"] = "Guest"
user_data["profile"]["lastName"] = "User"

if "id" in user_data:
user_create_response = okta_admin.update_user(user_id=user_data["id"], user=user_data)
Expand Down Expand Up @@ -189,18 +191,18 @@ def ecommerce_registration_completion():
def ecommerce_create_guest_account():
logger.debug("ecommerce_create_guest_account()")
okta_admin = OktaAdmin(session[SESSION_INSTANCE_SETTINGS_KEY])
guest_user_id = str(uuid.uuid4())
guest_user_id = str(uuid.uuid4()).replace('-', '')

user_data = {
"profile": {
"email": "{id}@guestuseraccount.com".format(id=guest_user_id),
"login": guest_user_id
"login": "{id}@guestuseraccount.com".format(id=guest_user_id),
"firstName": "Guest",
"lirstName": "User",
}
}

logger.debug(user_data)
response = okta_admin.create_user(user=user_data)
logger.debug(response)
return response


Expand Down
3 changes: 3 additions & 0 deletions utils/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def safe_assign_config_item(key, source_collection, target_collection):
# ENV always overrides source config
target_collection[key] = os.getenv(key.upper(), source_collection[key])

# if key == "redirect_uri":
# target_collection[key] = os.getenv("OKTA_OIDC_REDIRECT_URI", "")


def clear_session_setting():
logger.debug("clear_session_setting()")
Expand Down

0 comments on commit 6a701ed

Please sign in to comment.