Created
December 28, 2011 03:49
-
-
Save arjones/1526115 to your computer and use it in GitHub Desktop.
Mapping from Microsoft Membership .NET 2.0 to PlayFramework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models; | |
import java.util.Date; | |
import java.util.List; | |
import java.util.Set; | |
import java.util.UUID; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.OneToMany; | |
import javax.persistence.Temporal; | |
import javax.persistence.TemporalType; | |
import javax.persistence.Transient; | |
import play.data.validation.Email; | |
import play.data.validation.Required; | |
import play.db.jpa.JPA; | |
import play.db.jpa.Model; | |
@Entity(name = "users") | |
public class User extends Model { | |
@Transient | |
private final Date ZERO = new Date(0); | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
public String PKID; // = UUID.randomUUID().toString(); | |
@Required | |
public String Username; | |
public String ApplicationName = "SMX.Echo"; | |
@Required | |
public String Email; | |
@Required | |
public String Comment; | |
@Required | |
public String Password; | |
public boolean IsApproved = true; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date LastActivityDate = ZERO; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date LastLoginDate = ZERO; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date LastPasswordChangedDate = ZERO; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date CreationDate = new Date(); | |
public boolean IsOnLine = false; | |
public boolean IsLockedOut = false; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date LastLockedOutDate = ZERO; | |
public Integer FailedPasswordAttemptCount = 0; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date FailedPasswordAttemptWindowStart = ZERO; | |
public Integer FailedPasswordAnswerAttemptCount = 0; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date FailedPasswordAnswerAttemptWindowStart = ZERO; | |
public List<UserRole> getRoles() { | |
return UserRole.find("Username = ?", this.Username).fetch(); | |
} | |
@Override | |
public String toString() { | |
return this.Username + " (" + this.Comment + ")"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models; | |
import javax.persistence.EmbeddedId; | |
import javax.persistence.Entity; | |
import play.db.jpa.GenericModel; | |
@Entity(name = "usersinroles") | |
public class UserRole extends GenericModel { | |
@EmbeddedId | |
public UserRoleId id; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models; | |
import java.io.Serializable; | |
import javax.persistence.Embeddable; | |
@Embeddable | |
public class UserRoleId implements Serializable { | |
public static final long serialVersionUID = 201112280038L; | |
public String Username; | |
public String Rolename; | |
public String ApplicationName = "SMX.Echo"; | |
@Override | |
public int hashCode() { | |
final int prime = 31; | |
int result = 1; | |
result = prime * result + ((this.ApplicationName == null) ? 0 : this.ApplicationName.hashCode()); | |
result = prime * result + ((this.Rolename == null) ? 0 : this.Rolename.hashCode()); | |
result = prime * result + ((this.Username == null) ? 0 : this.Username.hashCode()); | |
return result; | |
} | |
@Override | |
public boolean equals(Object obj) { | |
if (this == obj) | |
return true; | |
if (obj == null) | |
return false; | |
if (getClass() != obj.getClass()) | |
return false; | |
UserRoleId other = (UserRoleId) obj; | |
if (this.ApplicationName == null) { | |
if (other.ApplicationName != null) | |
return false; | |
} else if (!this.ApplicationName.equals(other.ApplicationName)) | |
return false; | |
if (this.Rolename == null) { | |
if (other.Rolename != null) | |
return false; | |
} else if (!this.Rolename.equals(other.Rolename)) | |
return false; | |
if (this.Username == null) { | |
if (other.Username != null) | |
return false; | |
} else if (!this.Username.equals(other.Username)) | |
return false; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment