parent
d78244aa36
commit
ddd8498040
@ -1,75 +0,0 @@ |
||||
/* |
||||
This file is part of Libresonic. |
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
Libresonic is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors |
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus |
||||
*/ |
||||
package org.libresonic.player.command; |
||||
|
||||
import org.libresonic.player.controller.*; |
||||
|
||||
/** |
||||
* Command used in {@link PasswordSettingsController}. |
||||
* |
||||
* @author Sindre Mehus |
||||
*/ |
||||
public class PasswordSettingsCommand { |
||||
private String username; |
||||
private String password; |
||||
private String confirmPassword; |
||||
private boolean ldapAuthenticated; |
||||
private boolean toast; |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username = username; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public String getConfirmPassword() { |
||||
return confirmPassword; |
||||
} |
||||
|
||||
public void setConfirmPassword(String confirmPassword) { |
||||
this.confirmPassword = confirmPassword; |
||||
} |
||||
|
||||
public boolean isLdapAuthenticated() { |
||||
return ldapAuthenticated; |
||||
} |
||||
|
||||
public void setLdapAuthenticated(boolean ldapAuthenticated) { |
||||
this.ldapAuthenticated = ldapAuthenticated; |
||||
} |
||||
|
||||
public boolean isToast() { |
||||
return toast; |
||||
} |
||||
|
||||
public void setToast(boolean toast) { |
||||
this.toast = toast; |
||||
} |
||||
} |
@ -1,107 +0,0 @@ |
||||
/* |
||||
This file is part of Libresonic. |
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
Libresonic is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors |
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus |
||||
*/ |
||||
package org.libresonic.player.command; |
||||
|
||||
import org.apache.commons.lang.StringUtils; |
||||
|
||||
import org.libresonic.player.controller.PremiumSettingsController; |
||||
import org.libresonic.player.domain.LicenseInfo; |
||||
import org.libresonic.player.domain.User; |
||||
|
||||
/** |
||||
* Command used in {@link PremiumSettingsController}. |
||||
* |
||||
* @author Sindre Mehus |
||||
*/ |
||||
public class PremiumSettingsCommand { |
||||
|
||||
private String path; |
||||
private String brand; |
||||
private LicenseInfo licenseInfo; |
||||
private String licenseCode; |
||||
private boolean forceChange; |
||||
private boolean submissionError; |
||||
private User user; |
||||
private boolean toast; |
||||
|
||||
public String getPath() { |
||||
return path; |
||||
} |
||||
|
||||
public void setPath(String path) { |
||||
this.path = path; |
||||
} |
||||
|
||||
public String getBrand() { |
||||
return brand; |
||||
} |
||||
|
||||
public void setBrand(String brand) { |
||||
this.brand = brand; |
||||
} |
||||
|
||||
public LicenseInfo getLicenseInfo() { |
||||
return licenseInfo; |
||||
} |
||||
|
||||
public String getLicenseCode() { |
||||
return licenseCode; |
||||
} |
||||
|
||||
public void setLicenseCode(String licenseCode) { |
||||
this.licenseCode = StringUtils.trimToNull(licenseCode); |
||||
} |
||||
|
||||
public void setLicenseInfo(LicenseInfo licenseInfo) { |
||||
this.licenseInfo = licenseInfo; |
||||
} |
||||
|
||||
public boolean isForceChange() { |
||||
return forceChange; |
||||
} |
||||
|
||||
public void setForceChange(boolean forceChange) { |
||||
this.forceChange = forceChange; |
||||
} |
||||
|
||||
public boolean isSubmissionError() { |
||||
return submissionError; |
||||
} |
||||
|
||||
public void setSubmissionError(boolean submissionError) { |
||||
this.submissionError = submissionError; |
||||
} |
||||
|
||||
public void setUser(User user) { |
||||
this.user = user; |
||||
} |
||||
|
||||
public User getUser() { |
||||
return user; |
||||
} |
||||
|
||||
public void setToast(boolean toast) { |
||||
this.toast = toast; |
||||
} |
||||
|
||||
public boolean isToast() { |
||||
return toast; |
||||
} |
||||
} |
@ -1,60 +0,0 @@ |
||||
/* |
||||
This file is part of Libresonic. |
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
Libresonic is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors |
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus |
||||
*/ |
||||
package org.libresonic.player.controller; |
||||
|
||||
import org.springframework.web.servlet.mvc.*; |
||||
import org.libresonic.player.service.*; |
||||
import org.libresonic.player.command.*; |
||||
import org.libresonic.player.domain.*; |
||||
|
||||
import javax.servlet.http.*; |
||||
|
||||
/** |
||||
* Controller for the page used to change password. |
||||
* |
||||
* @author Sindre Mehus |
||||
*/ |
||||
public class PasswordSettingsController extends SimpleFormController { |
||||
|
||||
private SecurityService securityService; |
||||
|
||||
protected Object formBackingObject(HttpServletRequest request) throws Exception { |
||||
PasswordSettingsCommand command = new PasswordSettingsCommand(); |
||||
User user = securityService.getCurrentUser(request); |
||||
command.setUsername(user.getUsername()); |
||||
command.setLdapAuthenticated(user.isLdapAuthenticated()); |
||||
return command; |
||||
} |
||||
|
||||
protected void doSubmitAction(Object comm) throws Exception { |
||||
PasswordSettingsCommand command = (PasswordSettingsCommand) comm; |
||||
User user = securityService.getUserByName(command.getUsername()); |
||||
user.setPassword(command.getPassword()); |
||||
securityService.updateUser(user); |
||||
|
||||
command.setPassword(null); |
||||
command.setConfirmPassword(null); |
||||
command.setToast(true); |
||||
} |
||||
|
||||
public void setSecurityService(SecurityService securityService) { |
||||
this.securityService = securityService; |
||||
} |
||||
} |
@ -1,80 +0,0 @@ |
||||
/* |
||||
This file is part of Libresonic. |
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
Libresonic is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors |
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus |
||||
*/ |
||||
package org.libresonic.player.controller; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.springframework.validation.BindException; |
||||
import org.springframework.web.servlet.ModelAndView; |
||||
import org.springframework.web.servlet.mvc.SimpleFormController; |
||||
|
||||
import org.libresonic.player.command.PremiumSettingsCommand; |
||||
import org.libresonic.player.service.SecurityService; |
||||
import org.libresonic.player.service.SettingsService; |
||||
|
||||
/** |
||||
* Controller for the Subsonic Premium page. |
||||
* |
||||
* @author Sindre Mehus |
||||
*/ |
||||
public class PremiumSettingsController extends SimpleFormController { |
||||
|
||||
private SettingsService settingsService; |
||||
private SecurityService securityService; |
||||
|
||||
protected Object formBackingObject(HttpServletRequest request) throws Exception { |
||||
PremiumSettingsCommand command = new PremiumSettingsCommand(); |
||||
command.setPath(request.getParameter("path")); |
||||
command.setForceChange(request.getParameter("change") != null); |
||||
command.setLicenseInfo(settingsService.getLicenseInfo()); |
||||
command.setBrand(settingsService.getBrand()); |
||||
command.setUser(securityService.getCurrentUser(request)); |
||||
return command; |
||||
} |
||||
|
||||
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object com, BindException errors) |
||||
throws Exception { |
||||
PremiumSettingsCommand command = (PremiumSettingsCommand) com; |
||||
Date now = new Date(); |
||||
|
||||
settingsService.setLicenseCode(command.getLicenseCode()); |
||||
settingsService.setLicenseEmail(command.getLicenseInfo().getLicenseEmail()); |
||||
settingsService.setLicenseDate(now); |
||||
settingsService.save(); |
||||
settingsService.scheduleLicenseValidation(); |
||||
|
||||
// Reflect changes in view. The validator will validate the license asynchronously.
|
||||
command.setLicenseInfo(settingsService.getLicenseInfo()); |
||||
command.setToast(true); |
||||
|
||||
return new ModelAndView(getSuccessView(), errors.getModel()); |
||||
} |
||||
|
||||
public void setSettingsService(SettingsService settingsService) { |
||||
this.settingsService = settingsService; |
||||
} |
||||
|
||||
public void setSecurityService(SecurityService securityService) { |
||||
this.securityService = securityService; |
||||
} |
||||
} |
@ -1,46 +0,0 @@ |
||||
/* |
||||
This file is part of Libresonic. |
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
Libresonic is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors |
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus |
||||
*/ |
||||
package org.libresonic.player.validator; |
||||
|
||||
import org.springframework.validation.*; |
||||
import org.libresonic.player.command.*; |
||||
import org.libresonic.player.controller.*; |
||||
|
||||
/** |
||||
* Validator for {@link PasswordSettingsController}. |
||||
* |
||||
* @author Sindre Mehus |
||||
*/ |
||||
public class PasswordSettingsValidator implements Validator { |
||||
|
||||
public boolean supports(Class clazz) { |
||||
return clazz.equals(PasswordSettingsCommand.class); |
||||
} |
||||
|
||||
public void validate(Object obj, Errors errors) { |
||||
PasswordSettingsCommand command = (PasswordSettingsCommand) obj; |
||||
|
||||
if (command.getPassword() == null || command.getPassword().length() == 0) { |
||||
errors.rejectValue("password", "usersettings.nopassword"); |
||||
} else if (!command.getPassword().equals(command.getConfirmPassword())) { |
||||
errors.rejectValue("password", "usersettings.wrongpassword"); |
||||
} |
||||
} |
||||
} |
@ -1,53 +0,0 @@ |
||||
/* |
||||
This file is part of Libresonic. |
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
Libresonic is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors |
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus |
||||
*/ |
||||
package org.libresonic.player.validator; |
||||
|
||||
import org.springframework.validation.Errors; |
||||
import org.springframework.validation.Validator; |
||||
|
||||
import org.libresonic.player.command.PremiumSettingsCommand; |
||||
import org.libresonic.player.controller.PremiumSettingsController; |
||||
import org.libresonic.player.service.SettingsService; |
||||
|
||||
/** |
||||
* Validator for {@link PremiumSettingsController}. |
||||
* |
||||
* @author Sindre Mehus |
||||
*/ |
||||
public class PremiumSettingsValidator implements Validator { |
||||
private SettingsService settingsService; |
||||
|
||||
public boolean supports(Class clazz) { |
||||
return clazz.equals(PremiumSettingsCommand.class); |
||||
} |
||||
|
||||
public void validate(Object obj, Errors errors) { |
||||
PremiumSettingsCommand command = (PremiumSettingsCommand) obj; |
||||
|
||||
if (!settingsService.isLicenseValid(command.getLicenseInfo().getLicenseEmail(), command.getLicenseCode())) { |
||||
command.setSubmissionError(true); |
||||
errors.rejectValue("licenseCode", "premium.invalidlicense"); |
||||
} |
||||
} |
||||
|
||||
public void setSettingsService(SettingsService settingsService) { |
||||
this.settingsService = settingsService; |
||||
} |
||||
} |
Loading…
Reference in new issue