// Path: src/main/java/com/coding4people/mosquitoreport/api/models/Email.java
// @DynamoDBTable(tableName = "email")
// public class Email {
//     @DynamoDBHashKey
//     private String email;
//     
//     @DynamoDBAttribute
//     private String userguid;
//     
//     @DynamoDBAttribute
//     @JsonIgnore
//     private String password;
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getUserguid() {
//         return userguid;
//     }
// 
//     public void setUserguid(String userguid) {
//         this.userguid = userguid;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
//     
//     public static String encryptPassword(String rawPassword) {
//         return BCrypt.hashpw(rawPassword, BCrypt.gensalt(12));
//     }
//     
//     public static boolean checkPassword(String rawPassword, String password) {
//         if(null == password || !password.startsWith("$2a$")) {
//             throw new IllegalArgumentException("Invalid hash provided for comparison");
//         }
//         
//         return BCrypt.checkpw(rawPassword, password);
//     }
// }
// 
// Path: src/main/java/com/coding4people/mosquitoreport/api/models/PasswordResetToken.java
// @DynamoDBTable(tableName = "passwordresettoken")
// public class PasswordResetToken {
//     @DynamoDBHashKey
//     private String email;
//     
//     @DynamoDBRangeKey
//     private String expires;
//     
//     @DynamoDBAttribute
//     private String token;
//     
//     @DynamoDBAttribute
//     private String userguid;
//     
//     public String getEmail() {
//         return email;
//     }
//     
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getExpires() {
//         return expires;
//     }
// 
//     public void setExpires(String expires) {
//         this.expires = expires;
//     }
//     
//     public String getToken() {
//         return token;
//     }
//     
//     public void setToken(String token) {
//         this.token = token;
//     }
// 
//     public String getUserguid() {
//         return userguid;
//     }
// 
//     public void setUserguid(String userguid) {
//         this.userguid = userguid;
//     }
//     
//     public static String encryptToken(String rawToken) {
//         return BCrypt.hashpw(rawToken, BCrypt.gensalt(12));
//     }
//     
//     public static boolean checkToken(String rawToken, String token) {
//         if(null == token || !token.startsWith("$2a$")) {
//             throw new IllegalArgumentException("Invalid hash provided for comparison");
//         }
//         
//         return BCrypt.checkpw(rawToken, token);
//     }
// }
// 
// Path: src/main/java/com/coding4people/mosquitoreport/api/repositories/EmailRepository.java
// @Singleton
// public class EmailRepository extends Repository<Email> {
//     @Override
//     protected Class<Email> getType() {
//         return Email.class;
//     }
// }
// 
// Path: src/main/java/com/coding4people/mosquitoreport/api/repositories/PasswordResetTokenRepository.java
// @Singleton
// public class PasswordResetTokenRepository extends Repository<PasswordResetToken> {
//     @Override
//     protected Class<PasswordResetToken> getType() {
//         return PasswordResetToken.class;
//     }
// }


import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Base64;
import java.util.UUID;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import com.coding4people.mosquitoreport.api.models.Email;
import com.coding4people.mosquitoreport.api.models.PasswordResetToken;
import com.coding4people.mosquitoreport.api.repositories.EmailRepository;
import com.coding4people.mosquitoreport.api.repositories.PasswordResetTokenRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

package com.coding4people.mosquitoreport.api.controllers;





@Path("/reset-password")
public class ResetPasswordController {
    @Inject
    PasswordResetTokenRepository passwordResetTokenRepository;
    
    @Inject
    EmailRepository emailRepository;

    /**
     * @api {post} /reset-password/request Request a password reset token
     * @apiGroup User
     * 
     * @apiParam {String} email
     *
     * @apiParamExample {json} Request-Example:
     *     {
     *       "email": "test@test.org"
     *     }
     * 
     * @apiSuccessExample Success-Headers:
     *     HTTP/1.1 200 OK
     */
    @POST
    @Path("/request")
    @Consumes("application/json")
    @Produces("application/json;charset=UTF-8")
    public ObjectNode request(@Valid RequestResetPasswordInput input) {
        String code = UUID.randomUUID().toString();
        
        Email email = emailRepository.load(input.getEmail());
        
        PasswordResetToken token = new PasswordResetToken();

// Path: src/main/java/com/coding4people/mosquitoreport/api/models/Email.java
// @DynamoDBTable(tableName = "email")
// public class Email {
//     @DynamoDBHashKey
//     private String email;
//     
//     @DynamoDBAttribute
//     private String userguid;
//     
//     @DynamoDBAttribute
//     @JsonIgnore
//     private String password;
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getUserguid() {
//         return userguid;
//     }
// 
//     public void setUserguid(String userguid) {
//         this.userguid = userguid;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
//     
//     public static String encryptPassword(String rawPassword) {
//         return BCrypt.hashpw(rawPassword, BCrypt.gensalt(12));
//     }
//     
//     public static boolean checkPassword(String rawPassword, String password) {
//         if(null == password || !password.startsWith("$2a$")) {
//             throw new IllegalArgumentException("Invalid hash provided for comparison");
//         }
//         
//         return BCrypt.checkpw(rawPassword, password);
//     }
// }
// 
// Path: src/main/java/com/coding4people/mosquitoreport/api/models/PasswordResetToken.java
// @DynamoDBTable(tableName = "passwordresettoken")
// public class PasswordResetToken {
//     @DynamoDBHashKey
//     private String email;
//     
//     @DynamoDBRangeKey
//     private String expires;
//     
//     @DynamoDBAttribute
//     private String token;
//     
//     @DynamoDBAttribute
//     private String userguid;
//     
//     public String getEmail() {
//         return email;
//     }
//     
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getExpires() {
//         return expires;
//     }
// 
//     public void setExpires(String expires) {
//         this.expires = expires;
//     }
//     
//     public String getToken() {
//         return token;
//     }
//     
//     public void setToken(String token) {
//         this.token = token;
//     }
// 
//     public String getUserguid() {
//         return userguid;
//     }
// 
//     public void setUserguid(String userguid) {
//         this.userguid = userguid;
//     }
//     
//     public static String encryptToken(String rawToken) {
//         return BCrypt.hashpw(rawToken, BCrypt.gensalt(12));
//     }
//     
//     public static boolean checkToken(String rawToken, String token) {
//         if(null == token || !token.startsWith("$2a$")) {
//             throw new IllegalArgumentException("Invalid hash provided for comparison");
//         }
//         
//         return BCrypt.checkpw(rawToken, token);
//     }
// }
// 
// Path: src/main/java/com/coding4people/mosquitoreport/api/repositories/EmailRepository.java
// @Singleton
// public class EmailRepository extends Repository<Email> {
//     @Override
//     protected Class<Email> getType() {
//         return Email.class;
//     }
// }
// 
// Path: src/main/java/com/coding4people/mosquitoreport/api/repositories/PasswordResetTokenRepository.java
// @Singleton
// public class PasswordResetTokenRepository extends Repository<PasswordResetToken> {
//     @Override
//     protected Class<PasswordResetToken> getType() {
//         return PasswordResetToken.class;
//     }
// }


// Path: src/main/java/com/coding4people/mosquitoreport/api/controllers/ResetPasswordController.java
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Base64;
import java.util.UUID;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import com.coding4people.mosquitoreport.api.models.Email;
import com.coding4people.mosquitoreport.api.models.PasswordResetToken;
import com.coding4people.mosquitoreport.api.repositories.EmailRepository;
import com.coding4people.mosquitoreport.api.repositories.PasswordResetTokenRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

package com.coding4people.mosquitoreport.api.controllers;





@Path("/reset-password")
public class ResetPasswordController {
    @Inject
    PasswordResetTokenRepository passwordResetTokenRepository;
    
    @Inject
    EmailRepository emailRepository;

    /**
     * @api {post} /reset-password/request Request a password reset token
     * @apiGroup User
     * 
     * @apiParam {String} email
     *
     * @apiParamExample {json} Request-Example:
     *     {
     *       "email": "test@test.org"
     *     }
     * 
     * @apiSuccessExample Success-Headers:
     *     HTTP/1.1 200 OK
     */
    @POST
    @Path("/request")
    @Consumes("application/json")
    @Produces("application/json;charset=UTF-8")
    public ObjectNode request(@Valid RequestResetPasswordInput input) {
        String code = UUID.randomUUID().toString();
        
        Email email = emailRepository.load(input.getEmail());
        
        PasswordResetToken token = new PasswordResetToken();

        token.setEmail(email.getEmail());
