123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <meta name="description" content="">
- <meta name="author" content="">
- <link rel="icon" href="favicon.ico">
- <title>Mailer API client</title>
- <!-- Bootstrap core CSS -->
- <link href="dist/css/bootstrap.min.css" rel="stylesheet">
- <!-- Custom styles for this template -->
- <link href="dist/css/album.css" rel="stylesheet">
- </head>
- <body>
- <header>
- <div class="navbar navbar-dark bg-dark box-shadow">
- <div class="container d-flex justify-content-between">
- <a href="#" class="navbar-brand d-flex align-items-center">
- <strong>Mailer API client</strong>
- </a>
- <span class="btn btn-primary" id="new_user" style="float:right;top:0;">New user</span>
- <span class="btn btn-primary" id="new_passwd" style="float:right;top:0;">Password recovery</span>
- </div>
- </div>
- </header>
- <main role="main">
- <div class="album py-5 bg-light">
- <div class="container">
- <div class="row" id="user_container">
- <label>Retrieve mailbox from</label>
- <select id="user_selector" class="form-control"></select>
- </div>
- <hr>
- <div class="row" id="mailbox_container">
- </div>
- </div>
- </div>
- </main>
- <div class="modal modal-lg fade" id="new_user_modal" tabindex="-1" role="dialog" aria-labelledby="new_user_modal" aria-hidden="true">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title">Create a new user</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>Email</label>
- <input type="email" class="form-control" placeholder="email@domain.com" id="user_email">
- </div>
- <div class="form-group">
- <label>Firstname</label>
- <input type="text" class="form-control" placeholder="Manolo" id="user_firstname">
- </div>
- <div class="form-group">
- <label>Lastname</label>
- <input type="text" class="form-control" placeholder="Martinez" id="user_lastname">
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <span class="btn btn-primary" onclick="create_user();" data-dismiss="modal">Create</span>
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
- </div>
- </div>
- </div>
- </div>
-
- <div class="modal modal-lg fade" id="new_passwd_modal" tabindex="-1" role="dialog" aria-labelledby="new_passwd_modal" aria-hidden="true">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title">Password recovery</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>Email</label>
- <input type="email" class="form-control" placeholder="email@domain.com" id="recover_email">
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <span class="btn btn-primary" onclick="recover_passwd();" data-dismiss="modal">Create</span>
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
- </div>
- </div>
- </div>
- </div>
- <!-- Bootstrap core JavaScript
- ================================================== -->
- <!-- Placed at the end of the document so the pages load faster -->
- <script src="assets/js/vendor/jquery-slim.min.js"></script>
- <script src="assets/js/vendor/popper.min.js"></script>
- <script src="dist/js/bootstrap.min.js"></script>
- <script src="assets/js/vendor/holder.min.js"></script>
- <script>
- var tmp = "";
- $(document).ready(function(){
- $('#new_user').click(function(){$("#new_user_modal").modal().show();});
- $('#new_passwd').click(function(){$("#new_passwd_modal").modal().show();});
- $('#user_selector').change(function(){tmp = $("#user_selector").val();});
- update();
- setInterval(update, 1000);
- });
-
- function update(){
- get_mailbox();
- get_users();
- }
-
- function get_mailbox(){
- $.get('http://127.0.0.1:8080/api/v1/mailbox/'+$('#user_selector').val(), function(data) {
- $('#mailbox_container').html('');
- data.mails.forEach((item, i) => {
- $(email_assembler(item)).appendTo($('#mailbox_container'));
- });
- });
- }
-
- function get_users(){
- $.get('http://127.0.0.1:8080/api/v1/users', function(data) {
- $('#user_selector').html('');
- data.forEach((item, i) => {
- $(user_assembler(item)).appendTo($('#user_selector'));
- });
- });
- }
-
- function email_assembler(item){
- return $.parseHTML(`<div class="col-md-12">
- <div class="card mb-12 box-shadow">
- <div class="card-body">
- <span class="card-text">From: ${item.from.email}</span><br>
- <span class="card-text">To: ${item.to.email}</span><br>
- <span class="card-text">Subject: <strong>${item.subject}</strong></span>
- </div>
- <div class="card-body">
- <span class="card-text">${item.body}</span>
- </div>
- </div>
- </div>`);
- }
-
- function user_assembler(item){
- return $.parseHTML(`<option value="${item.email}" ${item.email == tmp ? 'selected' : ''}>${item.email}</option>`);
- }
-
- function create_user(){
- $.ajax({
- contentType: 'application/json',
- data: JSON.stringify({email:$('#user_email').val(), firstname:$('#user_firstname').val(), lastname:$('#user_lastname').val()}),
- dataType: 'json',
- type: 'POST',
- url: 'http://127.0.0.1:8080/api/v1/users'
- });
- $("#new_user_modal").modal().hide();
- }
-
- function recover_passwd(){
- $.ajax({
- type: 'POST',
- url: 'http://127.0.0.1:8080/api/v1/users/'+$('#recover_email').val()+'/passwd'
- });
- $("#new_passwd_modal").modal().hide();
- }
-
- </script>
- </body>
- </html>
|