Skip to content

Commit

Permalink
UI reworked. (#16)
Browse files Browse the repository at this point in the history
- not using a domain object for PortalUsers
- relying 100% to auth service
  • Loading branch information
leni-kirilov authored Jan 21, 2017
1 parent 18a9934 commit 00a287f
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 52 deletions.
4 changes: 2 additions & 2 deletions grails-app/controllers/cakecatalog/LoginController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LoginController {
}

if (!params.email || !params.password) {
flash.message = "Email or password are empty"
flash.message += "Email or password are empty"
redirect uri: '/'
return
}
Expand All @@ -32,7 +32,7 @@ class LoginController {
return
}

session['loggedUser'] = PortalUser.get(loggedUser.id)
session['loggedUser'] = loggedUser

redirect(
action: 'index',
Expand Down
33 changes: 18 additions & 15 deletions grails-app/controllers/cakecatalog/PortalUserController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.cakecatalog.srv.auth.client.AuthClient
import com.cakecatalog.srv.auth.client.model.PortalUserResponse
import grails.validation.ValidationErrors

import static org.springframework.http.HttpStatus.CREATED
import static org.springframework.http.HttpStatus.NOT_FOUND
import static org.springframework.http.HttpStatus.OK

Expand All @@ -25,7 +24,7 @@ class PortalUserController {
}

def create() {
respond new PortalUser(params)
respond new PortalUser()
}

def save(PortalUser portalUser) {
Expand All @@ -40,13 +39,11 @@ class PortalUserController {
createdPortalUser = authClient.createPortalUser(portalUser.name, portalUser.email, portalUser.password)
portalUser.id = createdPortalUser.id

request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'portalUser.label', default: 'PortalUser'), portalUser.id])
redirect portalUser
}
'*' { respond portalUser, [status: CREATED] }
}
flash.message = "New user created"
redirect(
action: 'index',
controller: 'cake',
)

} catch (Exception e) {
log.info e
Expand All @@ -55,26 +52,32 @@ class PortalUserController {
}
}

def edit(PortalUser portalUser) {
if (session['loggedUser']?.id == portalUser?.id) {
respond portalUser
def edit(Long id) {
log.info "Editting user with id: [$id]..."

if (session['loggedUser']?.id == id) {
respond convertToPortalUser(session['loggedUser'] as PortalUserResponse)
} else {
flash.message = "Cannot view this page as you don't own it. Your logged user${session['loggedUser']} vs required: ${portalUser?.id}"
flash.message = "Cannot view this page as you don't own it. Your logged user ${session['loggedUser']} vs required: $id"
redirect(
action: 'index',
controller: 'cake',
)
}
}

private static PortalUser convertToPortalUser(PortalUserResponse apiUser){
new PortalUser(name: apiUser.name, id: apiUser.id, email: apiUser.email)
}

def update(PortalUser portalUser) {
if (portalUser == null) {
notFound()
return
}

authClient.updatePortalUser(portalUser.id, portalUser.name, portalUser.password)
portalUser.refresh()
PortalUserResponse updatedPortalUser = authClient.updatePortalUser(portalUser.id, portalUser.name, portalUser.password)
session['loggedUser'] = updatedPortalUser

request.withFormat {
form multipartForm {
Expand Down
18 changes: 0 additions & 18 deletions grails-app/domain/cakecatalog/PortalUser.groovy

This file was deleted.

10 changes: 10 additions & 0 deletions grails-app/migrations/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@
</addColumn>
</changeSet>

<changeSet id="Remove portal user" author="Leni.Kirilov">

<preConditions onFail="MARK_RAN">
<tableExists tableName="portal_user"/>
</preConditions>

<dropTable tableName="portal_user"/>

</changeSet>

</databaseChangeLog>
2 changes: 1 addition & 1 deletion grails-app/views/cake/create.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ul>
<li><g:link controller="login" action="logout"><g:message code="Logout"/></g:link></li>
<li><g:link class="list" action="index"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
<li><g:link class="edit" controller="portalUser" action="edit" resource="${session['loggedUser']}">Edit profile</g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" id="${session['loggedUser'].id}" >Edit profile</g:link></li>
</ul>
</div>
<div id="create-cake" class="content scaffold-create" role="main">
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/cake/edit.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<li><g:link controller="login" action="logout"><g:message code="Logout"/></g:link></li>
<li><g:link class="list" action="index"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" resource="${session['loggedUser']}">Edit profile</g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" id="${session['loggedUser'].id}" >Edit profile</g:link></li>
</ul>
</div>
<div id="edit-cake" class="content scaffold-edit" role="main">
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/cake/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ul>
<li><g:link controller="login" action="logout"><g:message code="Logout"/></g:link></li>
<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" resource="${session['loggedUser']}">Edit profile</g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" id="${session['loggedUser'].id}" >Edit profile</g:link></li>
</ul>
</div>
<div id="list-cake" class="content scaffold-list" role="main">
Expand Down
4 changes: 2 additions & 2 deletions grails-app/views/cake/show.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<li><g:link controller="login" action="logout"><g:message code="Logout"/></g:link></li>
<li><g:link class="list" action="index"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" resource="${session['loggedUser']}">Edit profile</g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" id="${session['loggedUser'].id}" >Edit profile</g:link></li>
</ul>
</div>
<div id="show-cake" class="content scaffold-show" role="main">
<h1><g:message code="default.show.label" args="[entityName]" /></h1>
<g:if test="${flash.message}">
<div class="message" role="status">${flash.message}</div>
</g:if>
<f:display bean="cake" />
<f:display bean="cake" />
<g:form resource="${this.cake}" method="DELETE">
<fieldset class="buttons">
<g:if test="${session['loggedUser'].id == this.cake.ownerId }">
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/portalUser/create.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ul>
</g:hasErrors>

<g:form action="save">
<g:form action="save" controller="portalUser">
<fieldset class="form">
<f:field bean="portalUser" name="name" required="true" property="name"/>
<f:field bean="portalUser" name="email" required="true" property="email"/>
Expand Down
16 changes: 6 additions & 10 deletions grails-app/views/portalUser/edit.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@
</ul>
</div>
<div id="edit-portalUser" class="content scaffold-edit" role="main">
<h1><g:message code="default.edit.label" args="[entityName]" /></h1>
<h1><g:message code="default.edit.label" args="[entityName]" /> with email [${this.portalUser.email}]</h1>
<g:if test="${flash.message}">
<div class="message" role="status">${flash.message}</div>
</g:if>
<g:hasErrors bean="${this.portalUser}">
<ul class="errors" role="alert">
<g:eachError bean="${this.portalUser}" var="error">
<li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
</g:eachError>
</ul>
</g:hasErrors>

<g:form resource="${this.portalUser}" method="PUT">
<g:hiddenField name="version" value="${this.portalUser?.version}" />
<fieldset class="form">
<f:all bean="portalUser" except="id,email"/>
<f:field property="name" value="${this.portalUser?.name}"/>
<f:field property="password" required="true" >
<g:passwordField name="password"/>
</f:field>
</fieldset>
<fieldset class="buttons">
<input class="save" type="submit" value="${message(code: 'default.button.update.label', default: 'Update')}" />
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/portalUser/show.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<li><g:link controller="login" action="logout"><g:message code="Logout"/></g:link></li>
<li><g:link controller="cake" class="list" action="index"><g:message code="default.list.label" args="['Cake']" /></g:link></li>
<li><g:link controller="cake" class="create" action="create"><g:message code="default.new.label" args="['Cake']" /></g:link></li>
<li><g:link controller="portalUser" class="edit" action="edit" resource="${session['loggedUser']}">Edit profile</g:link></li>
<li><g:link class="edit" action="edit" controller="portalUser" id="${session['loggedUser'].id}" >Edit profile</g:link></li>
</ul>
</div>
<div id="show-portalUser" class="content scaffold-show" role="main">
Expand Down
10 changes: 10 additions & 0 deletions src/main/groovy/cakecatalog/PortalUser.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cakecatalog

class PortalUser {

Long id
long version
String name
String email
String password
}

0 comments on commit 00a287f

Please sign in to comment.