package be.jeffcheasey88.peeratcode.routes.users; import java.util.regex.Matcher; import org.jose4j.json.internal.json_simple.JSONObject; import be.jeffcheasey88.peeratcode.bonus.extract.RouteDoc; import be.jeffcheasey88.peeratcode.framework.HttpReader; import be.jeffcheasey88.peeratcode.framework.HttpWriter; import be.jeffcheasey88.peeratcode.framework.RequestType; import be.jeffcheasey88.peeratcode.framework.Response; import be.jeffcheasey88.peeratcode.framework.Route; import be.jeffcheasey88.peeratcode.framework.User; import be.jeffcheasey88.peeratcode.repository.DatabaseRepository; public class ChangePassword implements Response{ private DatabaseRepository repo; public ChangePassword(DatabaseRepository repo){ this.repo = repo; } @RouteDoc(path = "/user/cpw", responseCode = 200, responseDescription = "L'utilisateur a mis à jours sont mots de passe") @RouteDoc(responseCode = 400, responseDescription = "L'utilisateur a envoyer un mots de passe invalide") @Route(path = "^/user/cpw$", type = RequestType.POST, needLogin = true) public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception { String password = (String) reader.readJson().get("password"); repo.updatePassword(user.getId(), password); writer.response(200, "Access-Control-Allow-Origin: *"); } }