Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cc0a2f
commit e3cf118
Showing
14 changed files
with
481 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class UserController { | ||
|
||
def beforeInterceptor = [action:this.&auth, except:["login", "authenticate", "logout"]] | ||
|
||
def auth() { | ||
if( !(session?.user?.role == "admin") ){ | ||
flash.message = "You must be an administrator to perform that task." | ||
redirect(controller:"user", action:"login") | ||
return false | ||
} | ||
} | ||
|
||
def scaffold = User | ||
|
||
def login = {} | ||
|
||
def authenticate = { | ||
def user = User.findByLoginAndPassword(params.login, params.password) | ||
if(user){ | ||
session.user = user | ||
flash.message = "Hello ${user.name}!" | ||
redirect(controller:"entry", action:"list") | ||
}else{ | ||
flash.message = "Sorry, ${params.login}. Please try again." | ||
redirect(action:"login") | ||
} | ||
} | ||
|
||
def logout = { | ||
flash.message = "Goodbye ${session.user.name}" | ||
session.user = null | ||
redirect(controller:"entry", action:"list") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class LoginTagLib { | ||
|
||
def loginControl = { | ||
if(session.user){ | ||
out << "Hello ${session.user.name} " | ||
out << """[${link(action:"logout", controller:"user"){"Logout"}}]""" | ||
} else { | ||
out << """[${link(action:"login", controller:"user"){"Login"}}]""" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
<div id="header"> | ||
<p><g:link class="header-main" controller="entry">Blogito</g:link></p> | ||
<p class="header-sub">A tiny little blog</p> | ||
|
||
<div id="loginHeader"> | ||
<g:loginControl /> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<meta name="layout" content="main" /> | ||
<title>Create User</title> | ||
</head> | ||
<body> | ||
<div class="nav"> | ||
<span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span> | ||
<span class="menuButton"><g:link class="list" action="list">User List</g:link></span> | ||
</div> | ||
<div class="body"> | ||
<h1>Create User</h1> | ||
<g:if test="${flash.message}"> | ||
<div class="message">${flash.message}</div> | ||
</g:if> | ||
<g:hasErrors bean="${userInstance}"> | ||
<div class="errors"> | ||
<g:renderErrors bean="${userInstance}" as="list" /> | ||
</div> | ||
</g:hasErrors> | ||
<g:form action="save" method="post" > | ||
<div class="dialog"> | ||
<table> | ||
<tbody> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="login">Login:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'login','errors')}"> | ||
<input type="text" id="login" name="login" value="${fieldValue(bean:userInstance,field:'login')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="password">Password:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'password','errors')}"> | ||
<input type="password" id="password" name="password" value="${fieldValue(bean:userInstance,field:'password')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="name">Name:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'name','errors')}"> | ||
<input type="text" id="name" name="name" value="${fieldValue(bean:userInstance,field:'name')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="role">Role:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'role','errors')}"> | ||
<g:select id="role" name="role" from="${userInstance.constraints.role.inList}" value="${userInstance.role}" ></g:select> | ||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
<div class="buttons"> | ||
<span class="button"><input class="save" type="submit" value="Create" /></span> | ||
</div> | ||
</g:form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<meta name="layout" content="main" /> | ||
<title>Edit User</title> | ||
</head> | ||
<body> | ||
<div class="nav"> | ||
<span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span> | ||
<span class="menuButton"><g:link class="list" action="list">User List</g:link></span> | ||
<span class="menuButton"><g:link class="create" action="create">New User</g:link></span> | ||
</div> | ||
<div class="body"> | ||
<h1>Edit User</h1> | ||
<g:if test="${flash.message}"> | ||
<div class="message">${flash.message}</div> | ||
</g:if> | ||
<g:hasErrors bean="${userInstance}"> | ||
<div class="errors"> | ||
<g:renderErrors bean="${userInstance}" as="list" /> | ||
</div> | ||
</g:hasErrors> | ||
<g:form method="post" > | ||
<input type="hidden" name="id" value="${userInstance?.id}" /> | ||
<div class="dialog"> | ||
<table> | ||
<tbody> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="login">Login:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'login','errors')}"> | ||
<input type="text" id="login" name="login" value="${fieldValue(bean:userInstance,field:'login')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="password">Password:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'password','errors')}"> | ||
<input type="password" id="password" name="password" value="${fieldValue(bean:userInstance,field:'password')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="name">Name:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'name','errors')}"> | ||
<input type="text" id="name" name="name" value="${fieldValue(bean:userInstance,field:'name')}"/> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="role">Role:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'role','errors')}"> | ||
<g:select id="role" name="role" from="${userInstance.constraints.role.inList}" value="${userInstance.role}" ></g:select> | ||
</td> | ||
</tr> | ||
|
||
<tr class="prop"> | ||
<td valign="top" class="name"> | ||
<label for="entries">Entries:</label> | ||
</td> | ||
<td valign="top" class="value ${hasErrors(bean:userInstance,field:'entries','errors')}"> | ||
|
||
<ul> | ||
<g:each var="e" in="${userInstance?.entries?}"> | ||
<li><g:link controller="entry" action="show" id="${e.id}">${e?.encodeAsHTML()}</g:link></li> | ||
</g:each> | ||
</ul> | ||
<g:link controller="entry" params="['user.id':userInstance?.id]" action="create">Add Entry</g:link> | ||
|
||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
<div class="buttons"> | ||
<span class="button"><g:actionSubmit class="save" value="Update" /></span> | ||
<span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span> | ||
</div> | ||
</g:form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<meta name="layout" content="main" /> | ||
<title>User List</title> | ||
</head> | ||
<body> | ||
<div class="nav"> | ||
<span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span> | ||
<span class="menuButton"><g:link class="create" action="create">New User</g:link></span> | ||
</div> | ||
<div class="body"> | ||
<h1>User List</h1> | ||
<g:if test="${flash.message}"> | ||
<div class="message">${flash.message}</div> | ||
</g:if> | ||
<div class="list"> | ||
<table> | ||
<thead> | ||
<tr> | ||
|
||
<g:sortableColumn property="id" title="Id" /> | ||
|
||
<g:sortableColumn property="login" title="Login" /> | ||
|
||
<g:sortableColumn property="password" title="Password" /> | ||
|
||
<g:sortableColumn property="name" title="Name" /> | ||
|
||
<g:sortableColumn property="role" title="Role" /> | ||
|
||
</tr> | ||
</thead> | ||
<tbody> | ||
<g:each in="${userInstanceList}" status="i" var="userInstance"> | ||
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> | ||
|
||
<td><g:link action="show" id="${userInstance.id}">${fieldValue(bean:userInstance, field:'id')}</g:link></td> | ||
|
||
<td>${fieldValue(bean:userInstance, field:'login')}</td> | ||
|
||
<td>${fieldValue(bean:userInstance, field:'password')}</td> | ||
|
||
<td>${fieldValue(bean:userInstance, field:'name')}</td> | ||
|
||
<td>${fieldValue(bean:userInstance, field:'role')}</td> | ||
|
||
</tr> | ||
</g:each> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div class="paginateButtons"> | ||
<g:paginate total="${User.count()}" /> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.