mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
added registration on welcome page
This commit is contained in:
@@ -19,7 +19,7 @@ public class UserService extends GenericDAO<User> {
|
||||
@Inject
|
||||
PasswordEncryptionService encryptionService;
|
||||
|
||||
private User findByName(String name) {
|
||||
public User findByName(String name) {
|
||||
TypedQuery<User> query = em.createNamedQuery("User.byName", User.class);
|
||||
query.setParameter("name", name.toLowerCase());
|
||||
|
||||
@@ -46,12 +46,18 @@ public class UserService extends GenericDAO<User> {
|
||||
}
|
||||
|
||||
public User register(String name, String password, Collection<Role> roles) {
|
||||
return register(name, password, null, roles);
|
||||
}
|
||||
|
||||
public User register(String name, String password, String email,
|
||||
Collection<Role> roles) {
|
||||
if (findByName(name) != null) {
|
||||
return null;
|
||||
}
|
||||
User user = new User();
|
||||
byte[] salt = encryptionService.generateSalt();
|
||||
user.setName(name);
|
||||
user.setEmail(email);
|
||||
user.setSalt(salt);
|
||||
user.setPassword(encryptionService.getEncryptedPassword(password, salt));
|
||||
user.getRoles().add(new UserRole(user, Role.USER));
|
||||
|
||||
@@ -77,4 +77,12 @@ public class User extends AbstractModel {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.commafeed.frontend.pages.FaviconPage;
|
||||
import com.commafeed.frontend.pages.GoogleImportCallbackPage;
|
||||
import com.commafeed.frontend.pages.GoogleImportRedirectPage;
|
||||
import com.commafeed.frontend.pages.HomePage;
|
||||
import com.commafeed.frontend.pages.LoginPage;
|
||||
import com.commafeed.frontend.pages.WelcomePage;
|
||||
import com.commafeed.frontend.pages.LogoutPage;
|
||||
import com.commafeed.frontend.utils.exception.DisplayExceptionPage;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
mountPage("login", LoginPage.class);
|
||||
mountPage("welcome", WelcomePage.class);
|
||||
mountPage("logout", LogoutPage.class);
|
||||
mountPage("error", DisplayExceptionPage.class);
|
||||
mountPage("favicon", FaviconPage.class);
|
||||
@@ -135,7 +135,7 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
||||
|
||||
@Override
|
||||
protected Class<? extends WebPage> getSignInPageClass() {
|
||||
return LoginPage.class;
|
||||
return WelcomePage.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.commafeed.frontend.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class RegistrationRequest implements Serializable {
|
||||
|
||||
private String name;
|
||||
private String password;
|
||||
private String email;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
<html xmlns:wicket="http://wicket.apache.org">
|
||||
<head>
|
||||
<title>CommaFeed</title>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<div ng-app="commafeed" id="main" class="main">
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:wicket="http://wicket.apache.org">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>Login</h1>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span wicket:id="login"></span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.commafeed.frontend.pages;
|
||||
|
||||
import com.commafeed.frontend.pages.auth.LoginPanel;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LoginPage extends BasePage {
|
||||
|
||||
public LoginPage() {
|
||||
add(new LoginPanel("login"));
|
||||
}
|
||||
}
|
||||
21
src/main/java/com/commafeed/frontend/pages/WelcomePage.html
Normal file
21
src/main/java/com/commafeed/frontend/pages/WelcomePage.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:wicket="http://wicket.apache.org">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>CommaFeed</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="span6">
|
||||
<h3>Login</h3>
|
||||
<span wicket:id="login"></span>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<h3>Register</h3>
|
||||
<span wicket:id="register"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
13
src/main/java/com/commafeed/frontend/pages/WelcomePage.java
Normal file
13
src/main/java/com/commafeed/frontend/pages/WelcomePage.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.commafeed.frontend.pages;
|
||||
|
||||
import com.commafeed.frontend.pages.components.LoginPanel;
|
||||
import com.commafeed.frontend.pages.components.RegisterPanel;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class WelcomePage extends BasePage {
|
||||
|
||||
public WelcomePage() {
|
||||
add(new LoginPanel("login"));
|
||||
add(new RegisterPanel("register"));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.commafeed.frontend.pages.auth;
|
||||
|
||||
import org.apache.wicket.authroles.authentication.panel.SignInPanel;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LoginPanel extends SignInPanel {
|
||||
|
||||
public LoginPanel(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
.bs-fb ul {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.commafeed.frontend.pages.components;
|
||||
|
||||
import org.apache.wicket.behavior.AttributeAppender;
|
||||
import org.apache.wicket.feedback.IFeedbackMessageFilter;
|
||||
import org.apache.wicket.markup.ComponentTag;
|
||||
import org.apache.wicket.markup.head.IHeaderResponse;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.model.AbstractReadOnlyModel;
|
||||
|
||||
import com.commafeed.frontend.utils.WicketUtils;
|
||||
|
||||
import de.agilecoders.wicket.Bootstrap;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class BootstrapFeedbackPanel extends FeedbackPanel {
|
||||
|
||||
public BootstrapFeedbackPanel(String id) {
|
||||
super(id);
|
||||
init();
|
||||
}
|
||||
|
||||
public BootstrapFeedbackPanel(String id, IFeedbackMessageFilter filter) {
|
||||
super(id, filter);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setOutputMarkupPlaceholderTag(true);
|
||||
add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
|
||||
|
||||
@Override
|
||||
public String getObject() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (anyMessage()) {
|
||||
sb.append(" bs-fb alert");
|
||||
}
|
||||
if (anyErrorMessage()) {
|
||||
sb.append(" alert-error");
|
||||
} else {
|
||||
sb.append(" alert-success");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}));
|
||||
|
||||
get("feedbackul").add(new AttributeAppender("class", " unstyled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onComponentTag(ComponentTag tag) {
|
||||
tag.setName("div");
|
||||
super.onComponentTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHead(IHeaderResponse response) {
|
||||
super.renderHead(response);
|
||||
Bootstrap.renderHead(response);
|
||||
WicketUtils.loadCSS(response, BootstrapFeedbackPanel.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.commafeed.frontend.pages.components;
|
||||
|
||||
import org.apache.wicket.MarkupContainer;
|
||||
import org.apache.wicket.authroles.authentication.panel.SignInPanel;
|
||||
import org.apache.wicket.feedback.ContainerFeedbackMessageFilter;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LoginPanel extends SignInPanel {
|
||||
|
||||
public LoginPanel(String id) {
|
||||
super(id);
|
||||
replace(new BootstrapFeedbackPanel("feedback",
|
||||
new ContainerFeedbackMessageFilter(
|
||||
(MarkupContainer) get("signInForm"))));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:wicket="http://wicket.apache.org">
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<div wicket:id="feedback"></div>
|
||||
<form wicket:id="form" autocomplete="off">
|
||||
<div class="control-group">
|
||||
<label class="control-label">User Name</label>
|
||||
<div class="controls">
|
||||
<input type="text" wicket:id="name"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Password</label>
|
||||
<div class="controls">
|
||||
<input type="password" wicket:id="password"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Email address</label>
|
||||
<div class="controls">
|
||||
<input type="email" wicket:id="email"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<input type="submit" class="btn btn-primary" value="Register" />
|
||||
</div>
|
||||
</form>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.commafeed.frontend.pages.components;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.wicket.authentication.IAuthenticationStrategy;
|
||||
import org.apache.wicket.feedback.ContainerFeedbackMessageFilter;
|
||||
import org.apache.wicket.markup.html.form.EmailTextField;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.PasswordTextField;
|
||||
import org.apache.wicket.markup.html.form.RequiredTextField;
|
||||
import org.apache.wicket.markup.html.form.StatelessForm;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.validation.IValidatable;
|
||||
import org.apache.wicket.validation.IValidator;
|
||||
import org.apache.wicket.validation.ValidationError;
|
||||
import org.apache.wicket.validation.validator.StringValidator;
|
||||
|
||||
import com.commafeed.backend.dao.UserService;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.frontend.model.RegistrationRequest;
|
||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class RegisterPanel extends Panel {
|
||||
|
||||
@Inject
|
||||
UserService userService;
|
||||
|
||||
public RegisterPanel(String markupId) {
|
||||
super(markupId);
|
||||
|
||||
IModel<RegistrationRequest> model = Model.of(new RegistrationRequest());
|
||||
|
||||
Form<RegistrationRequest> form = new StatelessForm<RegistrationRequest>(
|
||||
"form", model) {
|
||||
@Override
|
||||
protected void onSubmit() {
|
||||
RegistrationRequest req = getModelObject();
|
||||
userService.register(req.getName(), req.getPassword(),
|
||||
Arrays.asList(Role.USER));
|
||||
IAuthenticationStrategy strategy = getApplication()
|
||||
.getSecuritySettings().getAuthenticationStrategy();
|
||||
strategy.save(req.getName(), req.getPassword());
|
||||
setResponsePage(getApplication().getHomePage());
|
||||
}
|
||||
};
|
||||
add(form);
|
||||
add(new BootstrapFeedbackPanel("feedback",
|
||||
new ContainerFeedbackMessageFilter(form)));
|
||||
|
||||
RegistrationRequest p = MF.p(RegistrationRequest.class);
|
||||
form.add(new RequiredTextField<String>("name", MF.m(model, p.getName()))
|
||||
.add(StringValidator.lengthBetween(3, 32)).add(
|
||||
new IValidator<String>() {
|
||||
@Override
|
||||
public void validate(
|
||||
IValidatable<String> validatable) {
|
||||
String name = validatable.getValue();
|
||||
User user = userService.findByName(name);
|
||||
if (user != null) {
|
||||
validatable.error(new ValidationError(
|
||||
"Name is already taken."));
|
||||
}
|
||||
}
|
||||
}));
|
||||
form.add(new PasswordTextField("password", MF.m(model, p.getPassword()))
|
||||
.setResetPassword(false).add(StringValidator.minimumLength(6)));
|
||||
form.add(new EmailTextField("email", MF.m(model, p.getEmail())));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user