Commit 33ce6414 by Tuukka Kivilahti

login with email

1 parent bb24b05a
......@@ -164,4 +164,11 @@ public interface UserBeanLocal {
EventUser getUser(String authcode);
String getAuthCode(EventUser user);
/**
* Find username by email or username, this is kind of login-helper.
* @param filter
* @return
*/
String findUsernameByEmailUsername(String filter);
}
......@@ -18,10 +18,7 @@
*/
package fi.codecrew.moya.beans;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import java.util.*;
import javax.ejb.EJB;
import javax.ejb.Stateless;
......@@ -97,6 +94,23 @@ public class JaasBean implements MoyaRealmBeanRemote {
} else {
user = eventUser.getUser();
}
// no user found, let's see if user is stupid and using email-address instead of username
// this is how it work's in theory, on practice, the fucking UserPrincipal get it's principal
// from used loginname, so, let's do this shit on loginview
/*if(user == null) {
List<User> users = userfacade.findByEmail(username);
// this must be 1, if there is more, it would just be quessing
logger.info("found by email some users {} ",users.size());
if(users.size() == 1) {
user = users.get(0);
eventUser = userbean.getEventUser(user,false);
}
}*/
logger.info("User '{}' with '{}' ", user, username);
// If there is no eventuser found, try to create one.
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
import java.security.Principal;
......
......@@ -1086,6 +1086,31 @@ public class UserBean implements UserBeanLocal {
}
@Override
public String findUsernameByEmailUsername(String filter) {
User user = userFacade.findByLogin(filter);
List<User> users = userFacade.findByEmail(filter);
if(users.size() == 1 && user != null) {
if(user.equals(users.get(0)))
return user.getLogin();
return null;
}
if(user != null)
return user.getLogin();
if(users.size() == 1) {
return users.get(0).getLogin();
}
return null;
}
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public EventUser getUser(String authcode) {
logger.info("getUser({})", authcode);
......
......@@ -18,8 +18,13 @@
<c:when test="#{not empty cc.attrs.isOneliner}">
<p:inputText styleClass="form" id="linelogin" value="#{authView.login}" />
<p:watermark for="linelogin" value="#{i18n['login.username']}" />
<p:password styleClass="form" id="linepwd" value="#{authView.password}" />
<p:commandButton styleClass="button" id="onelinesubmit" action="#{authView.executeLoginAction}" ajax="false" value="#{i18n['login.submit']}" />
<p:watermark for="linepwd" value="#{i18n['login.password']}" />
<p:commandButton update="messages" styleClass="button" id="onelinesubmit" action="#{authView.executeLoginAction}" ajax="false" value="#{i18n['login.submit']}" />
</c:when>
<c:otherwise>
......@@ -30,7 +35,7 @@
<p:password id="gridPwd" value="#{authView.password}" />
</h:panelGrid>
<p:commandButton id="gridsubmit" actionListener="#{authView.executeLogin(cc.attrs.onerror)}" ajax="false" value="#{i18n['login.submit']}" />
<p:commandButton update="messages" id="gridsubmit" actionListener="#{authView.executeLogin(cc.attrs.onerror)}" ajax="false" value="#{i18n['login.submit']}" />
</c:otherwise>
</c:choose>
......
......@@ -148,10 +148,13 @@
<div style="text-align: left; padding: 0.7em;">
<h:form>
<p:inputText styleClass="form" id="linelogin" value="#{authView.login}" />
<p:watermark for="linelogin" value="#{i18n['login.username']}" />
<br />
<p:password styleClass="form" id="linepwd" value="#{authView.password}" />
<br />
<p:commandButton styleClass="button" id="onelinesubmit" action="#{authView.executeLoginAction}" ajax="false" value="#{i18n['login.submit']}" />
<p:watermark for="linepwd" value="#{i18n['login.password']}" />
<br /><br />
<p:commandButton update="messages" styleClass="button" id="onelinesubmit" action="#{authView.executeLoginAction}" ajax="false" value="#{i18n['login.submit']}" />
<br /><br />
</h:form>
<ui:fragment rendered="#{authView.canCreateUser}">
<h:link value="#{i18n['submenu.user.create']}" outcome="/user/create" />
......
......@@ -29,6 +29,7 @@ import javax.inject.Named;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import fi.codecrew.moya.beans.UserBeanLocal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -60,6 +61,9 @@ public class AuthView extends GenericCDIView {
@EJB
private PermissionBeanLocal permbean;
@EJB
private UserBeanLocal userbean;
public boolean isCanCreateUser() {
return permbean.hasPermission(UserPermission.CREATE_NEW);
}
......@@ -149,18 +153,26 @@ public class AuthView extends GenericCDIView {
}
}
// first, let's make some blindshooting, email-login
String userlogin = userbean.findUsernameByEmailUsername(login.trim());
if(userlogin != null)
login = userlogin;
try {
request.login(login.trim().toLowerCase(), password);
} catch (Throwable e) {
logger.info("Error while trying to login {}", e.getMessage());
} finally {
Principal principal = request.getUserPrincipal();
logger.info("Logged in principal: {}", principal);
if (principal != null) {
navihandler.redirectToSaved();
} else {
navihandler.forward(onError);
try {
request.logout();
......
......@@ -278,7 +278,7 @@ login.logout = Logout
login.logoutmessage = You have logged out of the system
login.password = Password
login.submit = Login
login.username = Username
login.username = S\u00E4hk\u00F6posti tai k\u00E4ytt\u00E4j\u00E4tunnus
loginerror.header = Login failed
loginerror.message = Username of password incorrect.
......
......@@ -659,7 +659,7 @@ login.logout = Logout
login.logoutmessage = You have logged out of the system
login.password = Password
login.submit = Login
login.username = Username
login.username = Email or username
loginerror.header = Login failed
loginerror.message = Username of password incorrect.
......
......@@ -668,7 +668,7 @@ login.logout = Kirjaudu ulos
login.logoutmessage = Olet kirjautunut ulos j\u00E4rjestelm\u00E4st\u00E4.
login.password = Salasana
login.submit = Kirjaudu sis\u00E4\u00E4n
login.username = K\u00E4ytt\u00E4j\u00E4tunnus
login.username = S\u00E4hk\u00F6posti tai k\u00E4ytt\u00E4j\u00E4tunnus
loginerror.header = Kirjautuminen ep\u00E4onnistui
loginerror.message = K\u00E4ytt\u00E4j\u00E4tunnus tai salasana ei ollut oikein.
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!