|
@@ -26,6 +26,7 @@
|
|
|
</a>
|
|
|
<span class="btn btn-primary" id="btn_new_email" style="float:right;top:0;">New email</span>
|
|
|
<span class="btn btn-warning" id="btn_refresh" style="float:right;top:0;" onclick="update();">Refresh</span>
|
|
|
+ <span class="btn btn-secondary" id="btn_login" style="float:right;top:0;">Login</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</header>
|
|
@@ -36,6 +37,7 @@
|
|
|
<div class="row" id="user_container">
|
|
|
<label>Retrieve mailbox from</label>
|
|
|
<input type="text" id="user_selector" class="form-control" value="emmey.orlene@yopmail.com">
|
|
|
+ <span class="alert alert-warning" id="alert"></span>
|
|
|
</div>
|
|
|
<hr>
|
|
|
<div class="row" id="mailbox_container">
|
|
@@ -80,6 +82,35 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
+ <div class="modal modal-lg fade" id="login_modal" tabindex="-1" role="dialog" aria-labelledby="login_modal" aria-hidden="true">
|
|
|
+ <div class="modal-dialog" role="document">
|
|
|
+ <div class="modal-content">
|
|
|
+ <div class="modal-header">
|
|
|
+ <h5 class="modal-title">Login</h5>
|
|
|
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
|
+ <span aria-hidden="true">×</span>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ <div class="modal-body">
|
|
|
+ <form>
|
|
|
+ <div class="form-group">
|
|
|
+ <label>Username</label>
|
|
|
+ <input type="email" class="form-control" id="login_username">
|
|
|
+ </div>
|
|
|
+ <div class="form-group">
|
|
|
+ <label>Password</label>
|
|
|
+ <input type="password" class="form-control" id="login_password">
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
+ <div class="modal-footer">
|
|
|
+ <span class="btn btn-primary" onclick="do_login();" data-dismiss="modal">Login</span>
|
|
|
+ <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
|
|
|
|
|
|
<!-- Bootstrap core JavaScript
|
|
@@ -93,24 +124,56 @@
|
|
|
<script>
|
|
|
|
|
|
var tmp = "";
|
|
|
+ var token = "";
|
|
|
var api = "http://127.0.0.1:8080/api/v1";
|
|
|
+ var auth = "http://127.0.0.1:8080/auth/authenticate";
|
|
|
$(document).ready(function(){
|
|
|
- update();
|
|
|
+ $('#alert').hide();
|
|
|
$('#btn_new_email').click(function(){$("#new_mail_modal").modal().show();});
|
|
|
- //setInterval(update, 5000);
|
|
|
+ $('#btn_login').click(function(){$("#login_modal").modal().show();});
|
|
|
});
|
|
|
|
|
|
function update(){
|
|
|
get_mailbox();
|
|
|
}
|
|
|
|
|
|
+ function do_login(){
|
|
|
+ $.ajax({
|
|
|
+ contentType: 'application/json',
|
|
|
+ data: JSON.stringify({username:$('#login_username').val(),
|
|
|
+ password:$('#login_password').val()}),
|
|
|
+ dataType: 'json',
|
|
|
+ type: 'POST',
|
|
|
+ url: auth
|
|
|
+ })
|
|
|
+ .done(function(data) {
|
|
|
+ console.log(data.access_token);
|
|
|
+ token = data.access_token;
|
|
|
+ })
|
|
|
+ .fail(function(data, textStatus, xhr) {
|
|
|
+ $('#alert').text("Not autenticated").show();
|
|
|
+ setTimeout(close_alert, 5000);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
function get_mailbox(){
|
|
|
- $.get(`${api}/${$('#user_selector').val()}`, function(data) {
|
|
|
+ $.ajax({
|
|
|
+ type: 'GET',
|
|
|
+ url: `${api}/${$('#user_selector').val()}`,
|
|
|
+ headers: {
|
|
|
+ "Authorization": "Bearer "+token
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .done(function(data) {
|
|
|
$('#mailbox_container').html('');
|
|
|
- data.forEach((item, i) => {
|
|
|
- $(email_assembler(item)).appendTo($('#mailbox_container'));
|
|
|
+ data.forEach((item, i) => {
|
|
|
+ $(email_assembler(item)).appendTo($('#mailbox_container'));
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .fail(function(data, textStatus, xhr) {
|
|
|
+ $('#alert').text("Not autenticated").show();
|
|
|
+ setTimeout(close_alert, 5000);
|
|
|
});
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
function email_assembler(item){
|
|
@@ -139,11 +202,19 @@
|
|
|
body:$('#mail_body').val()}),
|
|
|
dataType: 'json',
|
|
|
type: 'POST',
|
|
|
+ headers: {
|
|
|
+ "Authorization": "Bearer "+token
|
|
|
+ },
|
|
|
url: api
|
|
|
})
|
|
|
.done(function(data) {
|
|
|
console.log(data);
|
|
|
+ })
|
|
|
+ .fail(function(data, textStatus, xhr) {
|
|
|
+ $('#alert').text("Not autenticated").show();
|
|
|
+ setTimeout(close_alert, 5000);
|
|
|
});
|
|
|
+
|
|
|
$("#new_mail_modal").modal().hide();
|
|
|
}
|
|
|
|
|
@@ -151,12 +222,23 @@
|
|
|
$.ajax({
|
|
|
url: `${api}/${id}`,
|
|
|
type: 'DELETE',
|
|
|
+ headers: {
|
|
|
+ "Authorization": "Bearer "+token
|
|
|
+ },
|
|
|
success: function(d) {
|
|
|
console.log(`#mail_elem_${d}`);
|
|
|
$(`#mail_elem_${d}`).remove();
|
|
|
}
|
|
|
+ })
|
|
|
+ .fail(function(data, textStatus, xhr) {
|
|
|
+ $('#alert').text("Not autenticated").show();
|
|
|
+ setTimeout(close_alert, 5000);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ function close_alert(){
|
|
|
+ $('#alert').hide();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
</script>
|