Skip to content

Commit

Permalink
Fix #387
Browse files Browse the repository at this point in the history
  • Loading branch information
pavels committed Mar 30, 2016
1 parent 683412f commit 4a8e3a7
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import cz.incad.kramerius.client.kapi.auth.ClientUser;
import cz.incad.kramerius.client.kapi.auth.ProfileDelegator;
import cz.incad.kramerius.client.kapi.auth.User;
import cz.incad.kramerius.client.kapi.auth.User.UserProvider;
import cz.incad.kramerius.client.kapi.auth.impl.CallUserControllerImpl;
import cz.incad.kramerius.client.socialauth.OpenIDSupport;
import cz.incad.kramerius.client.socialauth.ShibbolethSupport;
Expand Down Expand Up @@ -161,6 +162,47 @@ public void perform(String remoteAddr, HttpServletRequest req, HttpServletRespon
}
}
},

savepass {

@Override
public void perform(String remoteAddr, HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException, IOException, JSONException {
String npass = req.getParameter("pswd");
String oldpass = req.getParameter("opswd");

CallUserController callUserController = (cz.incad.kramerius.client.kapi.auth.CallUserController) req.getSession(true).getAttribute(CallUserController.KEY);
if (callUserController != null) {
ClientUser clientCaller = callUserController.getClientCaller();
// only k5 client
String callerPassword = clientCaller.getPassword();
if (callerPassword.equals(oldpass)) {
UserProvider userProvider = clientCaller.getUserProvider();
if (userProvider.equals(UserProvider.K5)) {
//
JSONObject jsonObject = new JSONObject();
jsonObject.put("pswd", npass);
String nprof = post(remoteAddr, jsonObject, clientCaller.getUserName(), clientCaller.getPassword());
if (nprof != null) {
synchronized(this) {
clientCaller.updatePassword(npass);
CallUserController.clearCredentials(clientCaller.getUserName());
CallUserController.credentialsTable(clientCaller.getUserName(),npass);
}
}
resp.getWriter().write(nprof);
resp.setContentType("application/json");
resp.setStatus(HttpServletResponse.SC_OK);
} else {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
} else {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
}

},


profile {
@Override
Expand Down Expand Up @@ -289,6 +331,7 @@ public void perform(String remoteAddr, HttpServletRequest req, HttpServletRespon
}
},


profile {
@Override
public void perform(String remoteAddr, HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException, IOException, JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public URLPathModify getPathModifier(String clzName) throws InstantiationExcepti


public static ClientResponse method(String url, SupportedMethods method,
JSONObject jsonObject, String userName, String pswd, String acceptMimeType)
JSONObject jsonObject, String userName, String pswd, String acceptMimeType, String contentType)
throws JSONException {
Client c = Client.create();

Expand All @@ -123,8 +123,8 @@ public static ClientResponse method(String url, SupportedMethods method,
Builder builder = r.accept(acceptMimeType);

if (jsonObject != null) {
builder = builder.type(acceptMimeType).entity(
jsonObject.toString(), acceptMimeType);
builder = builder.type(contentType).entity(
jsonObject.toString(), contentType);
}

switch (method) {
Expand Down Expand Up @@ -194,10 +194,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
ClientResponse clientResponse = null;
if (user != null) {
clientResponse = method(replaceURL, SupportedMethods.POST, jsonObj,
user.getUserName(), user.getPassword(), req.getHeader("Accept"));
user.getUserName(), user.getPassword(), req.getHeader("Accept"),req.getHeader("Content-Type"));
} else {
clientResponse = method(replaceURL, SupportedMethods.POST, jsonObj, null,
null, req.getHeader("Accept"));
null, req.getHeader("Accept"),req.getHeader("Content-Type"));
}
resp.setContentType(clientResponse.getType().toString());
resp.getWriter().write(clientResponse.getEntity(String.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public interface ClientUser extends User {

public void updateInformation(String fname, String sname);

public void updatePassword(String pswd);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ public UserProvider getUserProvider() {
return this.userProvider;
}

protected void updatePassword(String pswd) {
this.userPassword = pswd;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public void updateInformation(String fname, String sname) {
this.firstName = fname;
this.surname = sname;
}

@Override
public void updatePassword(String pswd) {
super.updatePassword(pswd);
}
}
19 changes: 19 additions & 0 deletions client/src/main/resources/k5client.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ application.help=Help
application.login=Login/Registration

application.logout=Logout

application.changepswd=Change password

application.profile=Profile

application.pdf=PDF
Expand Down Expand Up @@ -269,6 +272,22 @@ registration.repeatcaptcha.placeholder=Repeat captcha
registration.repeatcaptcha.error=(Missing field)
registration.badcaptcha.error=(Bad captcha field)

changepswd.display.success=Your password has been successfully changed!

changepswd.display=Change password
changepswd.button=Change password

changepswd.oldpassword=Current password
changepswd.oldpassword.placeholder=Current password

changepswd.newpassword=New password
changepswd.newpassword.placeholder=New password

changepswd.repeatnewpassword=Repeat new password
changepswd.repeatnewpassword.placeholder=Repeat new password

changepswd.error.1=New passwords do not match
changepswd.error.2=Bad old password

login.display=Login to digital library Vaclav Matej Kramerius v.5

Expand Down
23 changes: 22 additions & 1 deletion client/src/main/resources/k5client_cs.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
application.about=Digitální knihovna
application.help=Nápověda
application.login=Přihlášení/Registrace

application.logout=Odhlášení

application.changepswd=Změna hesla

application.profile=Profil

application.pdf=PDF
Expand Down Expand Up @@ -240,6 +242,24 @@ registration.repeatcaptcha.placeholder=Opište text z obrázku
registration.repeatcaptcha.error=(Chybející pole)
registration.badcaptcha.error=(špatný text)

changepswd.display.success=Heslo bylo úspěšně změněno!
changepswd.display=Změna hesla

changepswd.button=Změna hesla

changepswd.oldpassword=Nynější heslo
changepswd.oldpassword.placeholder=Nynější heslo

changepswd.newpassword=Nové heslo
changepswd.newpassword.placeholder=Nové heslo

changepswd.repeatnewpassword=Opakujte nové heslo
changepswd.repeatnewpassword.placeholder=Opakujte nové heslo

changepswd.error.1=Nová hesla nesedí
changepswd.error.2=Špatné původní heslo



login.display=Přihlášení do knihovny Václava Matěje Krameria ve verzi 5
login.registrationtext=Potřebujete účet? Registrujte se !
Expand All @@ -252,6 +272,7 @@ login.password=Heslo
login.password.placeholder=Heslo



login.options=Možnosti přihlášení
login.option.facebook=Přihlášení pomocí účtu Facebook
login.option.gplus=Přihlášení pomocí účtu Google plus
Expand Down
94 changes: 94 additions & 0 deletions client/src/main/webapp/WEB-INF/changepswd.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<style>

#changepswd{
z-index: 3;
top:2px;
left: 2px;
width: 100%;
}

#changepswdbox input{
font-size: 2.2em;
background: rgba(255, 255, 255, 0.9);
border: 0px solid #0e70b3;
width: 100%;
}

#changepswdbox input:hover{
background: rgba(255, 255, 255, 1);
}


#changepswdbox div.alternatives ul{
margin-top:0px;
}


#changepswdbox div.alternatives{
border-top:1px solid white;
margin-top:1em;
}

#changepswdbox div.alternatives ul {
padding-left:0px;
margin-top:.3em;
}

#changepswdbox div.alternatives li {
display:inline-block;
}

.login_error {
color:red;
}
</style>

<script type="text/javascript">
function __changepswdbutton() {
var oldpass = $("#opassword1").val();
var npass = $("#npassword1").val();
var npass2 = $("#npassword2").val();
if (npass === npass2) {
K5.authentication.changePassAndRedirect(oldpass,npass, 'index.vm?page=changepswd_success', 'index.vm?page=changepswd&error=true&type=badoldpass');
} else {
window.location.assign('index.vm?page=changepswd&error=true&type=badnewpass');
}
}

$( document ).ready( function() {
var err = getParameterByName("error");
if (err === "true") {
var type = getParameterByName("type");

$("#changepswdbox_error_"+type).show();
}
});

</script>

<div id="changepswd">
<div class="changepswdbox">

<div>
<h3> #translatable('changepswd.display') </h3>
</div>

<div id="changepswdbox">
<form id="changepswd_form" name="changepswd_form">
<label>#translatable('changepswd.oldpassword'):</label>
<input class="translate_placeholder" data-key="changepswd.oldpassword.placeholder" id="opassword1" name="password1" placeholder="#i18nval('changepswd.oldpassword.placeholder')" value="" type="password"/>
<label>#translatable('changepswd.newpassword'):</label>
<input class="translate_placeholder" data-key="changepswd.newpassword.placeholder" id="npassword1" name="password2" placeholder="#i18nval('changepswd.newpassword.placeholder')" value="" type="password" />
<label>#translatable('changepswd.repeatnewpassword'):</label>
<input class="translate_placeholder" data-key="changepswd.repeatnewpassword.placeholder" id="npassword2" name="npassword" placeholder="#i18nval('changepswd.repeatnewpassword.placeholder')" value="" type="password" />
</form>
</div>

<div class="button" onclick="__changepswdbutton()">
#translatable('changepswd.button')
</div>

<div id="changepswdbox_error_badoldpass" class="login_error" style="display:none">#translatable('changepswd.error.2')</div>
<div id="changepswdbox_error_badnewpass" class="login_error" style="display:none">#translatable('changepswd.error.1')</div>
</div>
</div>
61 changes: 61 additions & 0 deletions client/src/main/webapp/WEB-INF/changepswd_success.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<style>

#changepswd{
z-index: 3;
top:2px;
left: 2px;
width: 100%;
}

#changepswdbox input{
font-size: 2.2em;
background: rgba(255, 255, 255, 0.9);
border: 0px solid #0e70b3;
width: 100%;
}

#changepswdbox input:hover{
background: rgba(255, 255, 255, 1);
}


#changepswdbox div.alternatives ul{
margin-top:0px;
}


#changepswdbox div.alternatives{
border-top:1px solid white;
margin-top:1em;
}

#changepswdbox div.alternatives ul {
padding-left:0px;
margin-top:.3em;
}

#changepswdbox div.alternatives li {
display:inline-block;
}

.login_error {
color:red;
}
</style>

<script type="text/javascript">
function __changepswd_success() {
window.location.assign('index.vm');
}
</script>

<div id="changepswd">
<div class="changepswdbox">
<div>
<h3> #translatable('changepswd.display.success') </h3>
</div>
<div class="button" onclick="__changepswd_success()">
#translatable('common.close')
</div>
</div>
</div>
32 changes: 32 additions & 0 deletions client/src/main/webapp/WEB-INF/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,38 @@ li.public:before{
/** end of loginbox section */


/** changepswd section */
.changepswdbox {
position:absolute;
top: 50px;
left: 90px;

width: 50%;
border:0px solid rgba(0, 0, 0, 0.3);
color: $params.textColor;
box-shadow: rgba(0, 0, 0, 0.5) 4px 4px 8px 0px;
font-size: 1.5em;
padding: 15px;
background-color: $params.activeColor;
}

.changepswdbox:hover{
background-color: $params.activeColor;
}

#changepswd div.button{
display: inline-block;
border: solid 1px rgba(180, 180, 180, 0.4);
padding: 5px;
}

#changepswd div.button:hover{
color: $params.textColor;
border-color: rgba(255, 255, 255, 1);
}

/** end of changepswd section */

#viewer .pages{
top: 50px;
}
Expand Down
Loading

0 comments on commit 4a8e3a7

Please sign in to comment.