0
我的目標是創建一個用戶可以更改其數據的編輯頁面。如何用Grails中的SpringSecurity Core和UI編輯用戶(甚至是密碼)
這是我_form:
<div class="fieldcontain ${hasErrors(bean: user, field: 'firstName', 'error')} required">
<label for="firstName">
<g:message code="userSec.firstName.label" default="First Name" />
<span class="required-indicator">*</span>
</label>
<g:textField name="firstName" required="" value="${user?.firstName}"/>
</div>
<div class="fieldcontain ${hasErrors(bean: user, field: 'lastName', 'error')} required">
<label for="lastName">
<g:message code="userSec.lastName.label" default="Last Name" />
<span class="required-indicator">*</span>
</label>
<g:textField name="lastName" required="" value="${user?.lastName}"/>
</div>
<div class="fieldcontain ${hasErrors(bean: user, field: 'username', 'error')} required">
<label for="username">
<g:message code="userSec.username.label" default="Username" />
<span class="required-indicator">*</span>
</label>
<g:textField name="username" required="" value="${user?.username}"/>
</div>
<div class="fieldcontain ${hasErrors(bean: user, field: 'email', 'error')} required">
<label for="email">
<g:message code="userSec.email.label" default="Email" />
<span class="required-indicator">*</span>
</label>
<g:field type="email" name="email" required="" value="${user?.email}"/>
</div>
<div class="fieldcontain ${hasErrors(bean: command, field: 'password', 'error')} required">
<label for="password">
<g:message code="user.password.label" default="Password" />
<span class="required-indicator">*</span>
</label>
<g:field type="password" name="password" class="passwd" required="" value="${command.password}" />
<span id="result"></span>
</div>
<div class="fieldcontain ${hasErrors(bean: command, field: 'password2', 'error')} required">
<label for="password2">
<g:message code="user.password2.label" default="Password (again)" />
<span class="required-indicator">*</span>
</label>
<g:field type="password" name="password2" required="" value="${command.password2}" />
</div>
,這是我的編輯頁面:
<%@ page import="p2s.UserSec" %>
<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main">
<g:set var="entityName" value="${message(code: 'userSec.label', default: 'UserSec')}" />
<title><g:message code="default.edit.label" args="[entityName]" /></title>
</head>
<body>
<a href="#edit-userSec" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content…"/></a>
<div class="nav" role="navigation">
<ul>
<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
</ul>
</div>
<div id="edit-userSec" class="content scaffold-edit" role="main">
<h1><g:message code="default.edit.label" args="[entityName]" /></h1>
<g:if test="${flash.message}">
<div class="message" role="status">${flash.message}</div>
</g:if>
<g:hasErrors bean="${user}">
<ul class="errors" role="alert">
<g:eachError bean="${user}" 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 url="[resource:user, action:'update']" method="PUT" >
<g:hiddenField name="version" value="${user?.version}" />
<fieldset class="form">
<g:render template="form"/>
</fieldset>
<fieldset class="buttons">
<g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" />
</fieldset>
</g:form>
</div>
</body>
</html>
我怎樣才能讓用戶修改自己的數據?我在密碼方面遇到了很多麻煩,因爲我無法解碼密碼,並將密碼與用戶想要更改密碼時的密碼相匹配。
我想使用Spring方法來做到這一點。
感謝大家,對不起,如果這是一個簡單的問題,但我是新來的Grails。
你不解碼現有的密碼,你散列新的密碼並匹配散列。 – doelleri