remove variable attribute section for traits.
[sgn.git] / mason / brapiclient / authentication.mas
blob7ce1ea78793f4efe8ac626bdaa423e2fa84ce646
1 <%args>
2 </%args>
4 <div id="brapi_auth_home_div">
6     <div class="row">
7     <div class="col-sm-6">
8     <h4>Login</h4>
9     <input name="brapi_auth_login_username" id="brapi_auth_login_username" class="form-control" type="text" placeholder="Your Username" />
10     <input name="brapi_auth_login_password" id="brapi_auth_login_password" class="form-control" type="password" placeholder="Password" />
11     <button class="btn btn-primary" name="brapi_auth_login_submit" id="brapi_auth_login_submit">Login</button>
12     </div>
13     <div class="col-sm-6">
14     <h4>Logout</h4>
15     <button class="btn btn-danger" name="brapi_auth_logout_submit" id="brapi_auth_logout_submit">Logout</button>
16     </div>
17     </div>
19 </div>
21 <script>
23 jQuery(document).ready(function() {
24     jQuery("#brapi_auth_login_submit").click(function() {
25         jQuery.ajax( {
26           'url': jQuery('#brapi_home_url_select').val()+'/brapi/v1/token',
27           'method': 'POST',
28           'data': { 
29             'grant_type' : 'password',
30             'username' :  jQuery("#brapi_auth_login_username").val(),
31             'password' : jQuery("#brapi_auth_login_password").val()
32           },
33           'success': function(response) {
34             console.log(response);
35             //jQuery("#brapi_auth_home_div").empty().html("Successfully logged in!"+response);
36             alert('Successfully logged in!'+response.userDisplayName + response.expires_in);
37             //location.reload();
38           },
39           error: function(response) {
40             alert('An error occurred');
41           }
42         });
43     });
44     
45     jQuery("#brapi_auth_logout_submit").click(function() {
46         jQuery.ajax( {
47           'url': jQuery('#brapi_home_url_select').val()+'/brapi/v1/token',
48           'method': 'DELETE',
49           'success': function(response) {
50             console.log(response);
51             alert('Successfully logged out!');
52             //location.reload();
53           },
54           error: function(response) {
55             alert('An error occurred');
56           }
57         });
58     });
59 });
61 </script>