package ch.fusun.baron.core.command.base;
import ch.fusun.baron.core.command.GameCommand;
import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.core.rmi.User;
import ch.fusun.baron.core.service.UserService;
/**
* Creates a User with the specified name and password
*/
public class CreateUserCommand extends GameCommand {
private String name;
private String password;
@Inject
private transient UserService userService;
/**
* Constructor
*/
public CreateUserCommand() {
// Do nothing
}
/**
* Constructor
*
* @param name
* The user name
* @param password
* The password
*
*/
public CreateUserCommand(String name, String password) {
this.name = name;
this.password = password;
}
@Override
public boolean isAllowed() {
return !userService.exists(this.name);
}
@Override
public void execute() {
userService.createUser(new User(this.name, this.password));
}
}