use sessionStorage & add user admin pages
This commit is contained in:
		@ -417,3 +417,15 @@ func (app *application) ShowSubscriptions(w http.ResponseWriter, r *http.Request
 | 
			
		||||
		app.errorLog.Println(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) AllUsers(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	if err := app.renderTemplate(w, r, "all-users", &templateData{}); err != nil {
 | 
			
		||||
		app.errorLog.Println(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) OneUser(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	if err := app.renderTemplate(w, r, "one-user", &templateData{}); err != nil {
 | 
			
		||||
		app.errorLog.Println(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,8 @@ func (app *application) routes() http.Handler {
 | 
			
		||||
		mux.Get("/all-subscriptions", app.AllSubscriptions)
 | 
			
		||||
		mux.Get("/sales/{id}", app.ShowSale)
 | 
			
		||||
		mux.Get("/subscriptions/{id}", app.ShowSubscriptions)
 | 
			
		||||
		mux.Get("/all-users", app.AllUsers)
 | 
			
		||||
		mux.Get("/all-users/{id}", app.OneUser)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	// mux.Post("/virtual-terminal-payment-succeeded", app.VirtualTerminalPaymentSucceeded)
 | 
			
		||||
 | 
			
		||||
@ -29,9 +29,9 @@ All Sales
 | 
			
		||||
    import {showTable, currentPage} from "/static/js/all-sales.js"
 | 
			
		||||
 | 
			
		||||
    let curPage = currentPage;
 | 
			
		||||
    if (localStorage.getItem("cur-page") !== null) {
 | 
			
		||||
        curPage = localStorage.getItem("cur-page");
 | 
			
		||||
        localStorage.removeItem("cur-page");
 | 
			
		||||
    if (sessionStorage.getItem("cur-page") !== null) {
 | 
			
		||||
        curPage = sessionStorage.getItem("cur-page");
 | 
			
		||||
        sessionStorage.removeItem("cur-page");
 | 
			
		||||
    }
 | 
			
		||||
    showTable({{.API}}, pageSize, curPage);
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
@ -32,9 +32,9 @@ All Subscriptions
 | 
			
		||||
    import {showTable, currentPage} from "/static/js/all-subscriptions.js"
 | 
			
		||||
 | 
			
		||||
    let curPage = currentPage;
 | 
			
		||||
    if (localStorage.getItem("cur-page") !== null) {
 | 
			
		||||
        curPage = localStorage.getItem("cur-page");
 | 
			
		||||
        localStorage.removeItem("cur-page");
 | 
			
		||||
    if (sessionStorage.getItem("cur-page") !== null) {
 | 
			
		||||
        curPage = sessionStorage.getItem("cur-page");
 | 
			
		||||
        sessionStorage.removeItem("cur-page");
 | 
			
		||||
    }
 | 
			
		||||
    showTable({{.API}}, pageSize, curPage);
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										25
									
								
								cmd/web/templates/all-users.page.gohtml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								cmd/web/templates/all-users.page.gohtml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
{{ template "base". }}
 | 
			
		||||
{{ define "title" }}
 | 
			
		||||
All Users
 | 
			
		||||
{{ end }}
 | 
			
		||||
{{ define "content" }}
 | 
			
		||||
<h2 class="mt-5">All Admin users</h2>
 | 
			
		||||
<hr>
 | 
			
		||||
<div class="float-end">
 | 
			
		||||
    <a class="btn btn-outline-secondary" href="/admin/all-users/0">Add User</a>
 | 
			
		||||
</div>
 | 
			
		||||
<div class="clearfix"></div>
 | 
			
		||||
<table id="user-table" class="table table-striped">
 | 
			
		||||
    <thead>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <th>User</th>
 | 
			
		||||
            <th>Email</th>
 | 
			
		||||
        </tr>
 | 
			
		||||
    </thead>
 | 
			
		||||
    <tbody>
 | 
			
		||||
    </tbody>
 | 
			
		||||
</table>
 | 
			
		||||
{{ end }}
 | 
			
		||||
{{ define "js" }}
 | 
			
		||||
<script>let tbody = document.getElementById("user-table").getElementByTagName("tbody")[0]</script>
 | 
			
		||||
{{ end }}
 | 
			
		||||
@ -70,6 +70,12 @@
 | 
			
		||||
                                <li>
 | 
			
		||||
                                    <hr class="dropdown-divider">
 | 
			
		||||
                                </li>
 | 
			
		||||
                                <li>
 | 
			
		||||
                                    <a class="dropdown-item" href="/admin/all-users">All Users</a>
 | 
			
		||||
                                </li>
 | 
			
		||||
                                <li>
 | 
			
		||||
                                    <hr class="dropdown-divider">
 | 
			
		||||
                                </li>
 | 
			
		||||
                                <li>
 | 
			
		||||
                                    <a class="dropdown-item" href="/logout">Logout</a>
 | 
			
		||||
                                </li>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								cmd/web/templates/one-user.page.gohtml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								cmd/web/templates/one-user.page.gohtml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
{{ template "base". }}
 | 
			
		||||
{{ define "title" }}
 | 
			
		||||
Admin User
 | 
			
		||||
{{ end }}
 | 
			
		||||
{{ define "content" }}
 | 
			
		||||
<h2 class="mt-5">Admin user</h2>
 | 
			
		||||
<hr>
 | 
			
		||||
{{ end }}
 | 
			
		||||
{{ define "js" }}
 | 
			
		||||
{{ end }}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user