Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Max Mecklin
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 33ce6414
authored
Dec 08, 2014
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login with email
1 parent
bb24b05a
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
95 additions
and
29 deletions
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/UserBeanLocal.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/JaasBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PermissionBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/UserBean.java
code/moya-web/WebContent/resources/cditools/login/login.xhtml
code/moya-web/WebContent/resources/templates/primelayout/template.xhtml
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/user/AuthView.java
code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n.properties
code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n_en.properties
code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n_fi.properties
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/UserBeanLocal.java
View file @
33ce641
...
@@ -164,4 +164,11 @@ public interface UserBeanLocal {
...
@@ -164,4 +164,11 @@ public interface UserBeanLocal {
EventUser
getUser
(
String
authcode
);
EventUser
getUser
(
String
authcode
);
String
getAuthCode
(
EventUser
user
);
String
getAuthCode
(
EventUser
user
);
/**
* Find username by email or username, this is kind of login-helper.
* @param filter
* @return
*/
String
findUsernameByEmailUsername
(
String
filter
);
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/JaasBean.java
View file @
33ce641
...
@@ -18,10 +18,7 @@
...
@@ -18,10 +18,7 @@
*/
*/
package
fi
.
codecrew
.
moya
.
beans
;
package
fi
.
codecrew
.
moya
.
beans
;
import
java.util.Enumeration
;
import
java.util.*
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Vector
;
import
javax.ejb.EJB
;
import
javax.ejb.EJB
;
import
javax.ejb.Stateless
;
import
javax.ejb.Stateless
;
...
@@ -97,6 +94,23 @@ public class JaasBean implements MoyaRealmBeanRemote {
...
@@ -97,6 +94,23 @@ public class JaasBean implements MoyaRealmBeanRemote {
}
else
{
}
else
{
user
=
eventUser
.
getUser
();
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
);
logger
.
info
(
"User '{}' with '{}' "
,
user
,
username
);
// If there is no eventuser found, try to create one.
// If there is no eventuser found, try to create one.
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PermissionBean.java
View file @
33ce641
/*
/*
* Copyright Codecrew Ry
* Copyright Codecrew Ry
*
*
* All rights reserved.
* All rights reserved.
*
*
* This license applies to any software containing a notice placed by the
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
* This license covers modification, distribution and use of the Software.
*
*
* Any distribution and use in source and binary forms, with or without
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* modification is not permitted without explicit written permission from the
* copyright owner.
* copyright owner.
*
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* 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
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
* future versions of the Software.
*
*
*/
*/
package
fi
.
codecrew
.
moya
.
beans
;
package
fi
.
codecrew
.
moya
.
beans
;
import
java.security.Principal
;
import
java.security.Principal
;
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/UserBean.java
View file @
33ce641
...
@@ -1086,6 +1086,31 @@ public class UserBean implements UserBeanLocal {
...
@@ -1086,6 +1086,31 @@ public class UserBean implements UserBeanLocal {
}
}
@Override
@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
)
@RolesAllowed
(
EventPermission
.
S_MANAGE_EVENT
)
public
EventUser
getUser
(
String
authcode
)
{
public
EventUser
getUser
(
String
authcode
)
{
logger
.
info
(
"getUser({})"
,
authcode
);
logger
.
info
(
"getUser({})"
,
authcode
);
...
...
code/moya-web/WebContent/resources/cditools/login/login.xhtml
View file @
33ce641
...
@@ -18,8 +18,13 @@
...
@@ -18,8 +18,13 @@
<c:when
test=
"#{not empty cc.attrs.isOneliner}"
>
<c:when
test=
"#{not empty cc.attrs.isOneliner}"
>
<p:inputText
styleClass=
"form"
id=
"linelogin"
value=
"#{authView.login}"
/>
<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: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:when>
<c:otherwise>
<c:otherwise>
...
@@ -30,7 +35,7 @@
...
@@ -30,7 +35,7 @@
<p:password
id=
"gridPwd"
value=
"#{authView.password}"
/>
<p:password
id=
"gridPwd"
value=
"#{authView.password}"
/>
</h:panelGrid>
</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:otherwise>
</c:choose>
</c:choose>
...
...
code/moya-web/WebContent/resources/templates/primelayout/template.xhtml
View file @
33ce641
...
@@ -148,10 +148,13 @@
...
@@ -148,10 +148,13 @@
<div
style=
"text-align: left; padding: 0.7em;"
>
<div
style=
"text-align: left; padding: 0.7em;"
>
<h:form>
<h:form>
<p:inputText
styleClass=
"form"
id=
"linelogin"
value=
"#{authView.login}"
/>
<p:inputText
styleClass=
"form"
id=
"linelogin"
value=
"#{authView.login}"
/>
<p:watermark
for=
"linelogin"
value=
"#{i18n['login.username']}"
/>
<br
/>
<br
/>
<p:password
styleClass=
"form"
id=
"linepwd"
value=
"#{authView.password}"
/>
<p:password
styleClass=
"form"
id=
"linepwd"
value=
"#{authView.password}"
/>
<br
/>
<p:watermark
for=
"linepwd"
value=
"#{i18n['login.password']}"
/>
<p:commandButton
styleClass=
"button"
id=
"onelinesubmit"
action=
"#{authView.executeLoginAction}"
ajax=
"false"
value=
"#{i18n['login.submit']}"
/>
<br
/><br
/>
<p:commandButton
update=
"messages"
styleClass=
"button"
id=
"onelinesubmit"
action=
"#{authView.executeLoginAction}"
ajax=
"false"
value=
"#{i18n['login.submit']}"
/>
<br
/><br
/>
</h:form>
</h:form>
<ui:fragment
rendered=
"#{authView.canCreateUser}"
>
<ui:fragment
rendered=
"#{authView.canCreateUser}"
>
<h:link
value=
"#{i18n['submenu.user.create']}"
outcome=
"/user/create"
/>
<h:link
value=
"#{i18n['submenu.user.create']}"
outcome=
"/user/create"
/>
...
...
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/user/AuthView.java
View file @
33ce641
...
@@ -29,6 +29,7 @@ import javax.inject.Named;
...
@@ -29,6 +29,7 @@ import javax.inject.Named;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
fi.codecrew.moya.beans.UserBeanLocal
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -60,6 +61,9 @@ public class AuthView extends GenericCDIView {
...
@@ -60,6 +61,9 @@ public class AuthView extends GenericCDIView {
@EJB
@EJB
private
PermissionBeanLocal
permbean
;
private
PermissionBeanLocal
permbean
;
@EJB
private
UserBeanLocal
userbean
;
public
boolean
isCanCreateUser
()
{
public
boolean
isCanCreateUser
()
{
return
permbean
.
hasPermission
(
UserPermission
.
CREATE_NEW
);
return
permbean
.
hasPermission
(
UserPermission
.
CREATE_NEW
);
}
}
...
@@ -149,18 +153,26 @@ public class AuthView extends GenericCDIView {
...
@@ -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
{
try
{
request
.
login
(
login
.
trim
().
toLowerCase
(),
password
);
request
.
login
(
login
.
trim
().
toLowerCase
(),
password
);
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
logger
.
info
(
"Error while trying to login {}"
,
e
.
getMessage
());
logger
.
info
(
"Error while trying to login {}"
,
e
.
getMessage
());
}
finally
{
}
finally
{
Principal
principal
=
request
.
getUserPrincipal
();
Principal
principal
=
request
.
getUserPrincipal
();
logger
.
info
(
"Logged in principal: {}"
,
principal
);
logger
.
info
(
"Logged in principal: {}"
,
principal
);
if
(
principal
!=
null
)
{
if
(
principal
!=
null
)
{
navihandler
.
redirectToSaved
();
navihandler
.
redirectToSaved
();
}
else
{
}
else
{
navihandler
.
forward
(
onError
);
navihandler
.
forward
(
onError
);
try
{
try
{
request
.
logout
();
request
.
logout
();
...
...
code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n.properties
View file @
33ce641
...
@@ -278,7 +278,7 @@ login.logout = Logout
...
@@ -278,7 +278,7 @@ login.logout = Logout
login.logoutmessage
=
You have logged out of the system
login.logoutmessage
=
You have logged out of the system
login.password
=
Password
login.password
=
Password
login.submit
=
Login
login.submit
=
Login
login.username
=
Username
login.username
=
S
\u
00E4hk
\u
00F6posti tai k
\u
00E4ytt
\u
00E4j
\u
00E4tunnus
loginerror.header
=
Login failed
loginerror.header
=
Login failed
loginerror.message
=
Username of password incorrect.
loginerror.message
=
Username of password incorrect.
...
...
code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n_en.properties
View file @
33ce641
...
@@ -659,7 +659,7 @@ login.logout = Logout
...
@@ -659,7 +659,7 @@ login.logout = Logout
login.logoutmessage
=
You have logged out of the system
login.logoutmessage
=
You have logged out of the system
login.password
=
Password
login.password
=
Password
login.submit
=
Login
login.submit
=
Login
login.username
=
U
sername
login.username
=
Email or u
sername
loginerror.header
=
Login failed
loginerror.header
=
Login failed
loginerror.message
=
Username of password incorrect.
loginerror.message
=
Username of password incorrect.
...
...
code/moya-web/src/main/resources/fi/codecrew/moya/resources/i18n_fi.properties
View file @
33ce641
...
@@ -668,7 +668,7 @@ login.logout = Kirjaudu ulos
...
@@ -668,7 +668,7 @@ login.logout = Kirjaudu ulos
login.logoutmessage
=
Olet kirjautunut ulos j
\u
00E4rjestelm
\u
00E4st
\u
00E4.
login.logoutmessage
=
Olet kirjautunut ulos j
\u
00E4rjestelm
\u
00E4st
\u
00E4.
login.password
=
Salasana
login.password
=
Salasana
login.submit
=
Kirjaudu sis
\u
00E4
\u
00E4n
login.submit
=
Kirjaudu sis
\u
00E4
\u
00E4n
login.username
=
K
\u
00E4ytt
\u
00E4j
\u
00E4tunnus
login.username
=
S
\u
00E4hk
\u
00F6posti tai k
\u
00E4ytt
\u
00E4j
\u
00E4tunnus
loginerror.header
=
Kirjautuminen ep
\u
00E4onnistui
loginerror.header
=
Kirjautuminen ep
\u
00E4onnistui
loginerror.message
=
K
\u
00E4ytt
\u
00E4j
\u
00E4tunnus tai salasana ei ollut oikein.
loginerror.message
=
K
\u
00E4ytt
\u
00E4j
\u
00E4tunnus tai salasana ei ollut oikein.
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment