Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Fix generate api issue
Browse files Browse the repository at this point in the history
https://bugzilla.redhat.com/show_bug.cgi?id=119359

Squashed commit of the following:

commit 1835b47
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Feb 20 10:39:10 2015 +1000

    Fix generate api issue: https://bugzilla.redhat.com/show_bug.cgi?id=1193597
  • Loading branch information
Alex Eng committed Feb 20, 2015
1 parent 4a20195 commit b078732
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Expand Up @@ -28,17 +28,15 @@
import java.util.List;

import javax.faces.context.ExternalContext;
import javax.mail.internet.InternetAddress;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Size;

import com.googlecode.totallylazy.collections.PersistentMap;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang.StringEscapeUtils;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.seam.ScopeType;
Expand All @@ -55,7 +53,6 @@
import org.zanata.dao.AccountDAO;
import org.zanata.dao.CredentialsDAO;
import org.zanata.dao.PersonDAO;
import org.zanata.email.EmailStrategy;
import org.zanata.i18n.Messages;
import org.zanata.model.HAccount;
import org.zanata.model.HLocale;
Expand Down Expand Up @@ -307,6 +304,14 @@ private String getKeyPrefix() {
return serverName.replace(".", "_");
}

/**
* return javascript safe message
*/
public String getRegenerateAPiKeyMsg() {
String msg = msgs.get("jsf.apikey.ConfirmGenerate");
return StringEscapeUtils.escapeJavaScript(msg);
}

public void regenerateApiKey() {
HAccount account =
accountDAO.findById(authenticatedAccount.getId());
Expand Down
18 changes: 13 additions & 5 deletions zanata-war/src/main/webapp/WEB-INF/layout/dashboard/settings.xhtml
Expand Up @@ -6,10 +6,6 @@
xmlns:a4j="http://richfaces.org/a4j"
xmlns:zanata="http://java.sun.com/jsf/composite/zanata">

<a4j:jsFunction name="regenerateApiKey"
action="#{userSettingsAction.regenerateApiKey}"
render="apiKeyForm" status="client-loader"/>

<h1>#{msgs['jsf.dashboard.settings.title']}</h1>
<div class="tabs--vertical js-tabs">
<ul class="tabs__nav js-tabs-nav">
Expand Down Expand Up @@ -273,6 +269,11 @@
#{msgs['jsf.dashboard.settings.clientSettings.label']}
</h2>
<h:form id="apiKeyForm">
<a4j:jsFunction name="regenerateApiKey"
action="#{userSettingsAction.regenerateApiKey}"
render="apiKeyForm" status="client-loader"
limitRender="true"/>

<p class="txt--meta">
<h:outputText value="#{msgs['jsf.dashboard.settings.apiKeyNeeded.message']}"/>
<a href="http://zanata.org/help/cli/cli-configuration/"
Expand Down Expand Up @@ -301,8 +302,15 @@
</p>
</s:fragment>
</div>
<script>
function confirmGenerateApiKey() {
if (confirm("#{userSettingsAction.regenerateAPiKeyMsg}")) {
regenerateApiKey();
}
}
</script>
<button id="generateKeyButton" class="button"
onclick="if (confirm('#{msgs['jsf.apikey.ConfirmGenerate']}')) {regenerateApiKey();} return false;">
onclick="confirmGenerateApiKey();return false;">
#{msgs['jsf.dashboard.settings.generateNewApiKey.label']}
</button>
<div class="form__item l--push-top-1">
Expand Down

0 comments on commit b078732

Please sign in to comment.