/**
 * Yona, 21st Century Project Hosting SW
 * <p>
 * Copyright Yona & Yobi Authors & NAVER Corp.
 * https://yona.io
 **/
package models;

import play.db.ebean.Model;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Entity
public class UserVerification extends Model {
    private static final long serialVersionUID = 7819377239127603471L;

    public static final Model.Finder<Long, UserVerification> find = new Finder<>(Long.class, UserVerification.class);

    @Id
    public Long id;

    @OneToOne
    public User user;

    public String loginId;

    public String verificationCode;

    public Long timestamp;

    public static UserVerification newVerification(User user) {
        UserVerification v = new UserVerification();
        v.user = user;
        v.loginId = user.loginId;
        v.verificationCode = UUID.randomUUID().toString();
        v.timestamp = new Date().getTime();
        v.save();
        return v;
    }

    public static UserVerification findbyUser(User user) {
        List<UserVerification> list = find.where().eq("user.id", user.id).findList();
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }

    public static UserVerification findbyLoginIdAndVerificationCode(String loginId, String verificationCode) {
        List<UserVerification> list = find.where().eq("login_id", loginId)
                .eq("verificationCode", verificationCode).findList();
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }

    public boolean isValidDate(){
        if( this.timestamp + 60*60*24  > new Date().getTime()) {
            return true;
        } else {
            this.delete();
            return false;
        }
    }

    public void invalidate(){
        this.delete();
    }
}

@@ -743,32 +743,45 @@
   public static 
+synchronized 
 UserVerification
@@ -1814,16 +1814,21 @@
 60*60*24
+*1000
   %3E new 
@@ -1932,90 +1932,534 @@
     
-return false;%0A        %7D%0A    %7D%0A%0A    public void invalidate()%7B%0A        this.delete()
+play.Logger.error(%22Email validation is expired: %22 + this.loginId + %22:%22 + this.verificationCode);%0A            return false;%0A        %7D%0A    %7D%0A%0A    public void invalidate()%7B%0A        this.delete();%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return %22UserVerification%7B%22 +%0A                %22id=%22 + id +%0A                %22, user=%22 + user +%0A                %22, loginId='%22 + loginId + '%5C'' +%0A                %22, verificationCode='%22 + verificationCode + '%5C'' +%0A                %22, timestamp=%22 + timestamp +%0A                '%7D'
 ;%0A  

Fix validation code expiring check bug