001/* 002 * Stallion Core: A Modern Web Framework 003 * 004 * Copyright (C) 2015 - 2016 Stallion Software LLC. 005 * 006 * This program is free software: you can redistribute it and/or modify it under the terms of the 007 * GNU General Public License as published by the Free Software Foundation, either version 2 of 008 * the License, or (at your option) any later version. This program is distributed in the hope that 009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 011 * License for more details. You should have received a copy of the GNU General Public License 012 * along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. 013 * 014 * 015 * 016 */ 017 018package io.stallion.users; 019 020import com.fasterxml.jackson.annotation.JsonIgnore; 021import com.fasterxml.jackson.annotation.JsonView; 022import io.stallion.dataAccess.Model; 023import io.stallion.dataAccess.file.ModelWithFilePath; 024import io.stallion.email.Contactable; 025import io.stallion.utils.json.RestrictedViews; 026 027import java.lang.String; 028import java.util.List; 029 030public interface IUser extends Contactable, Model, ModelWithFilePath { 031 032 033 public String getUsername(); 034 public String getDisplayName(); 035 public String getGivenName(); 036 public String getFamilyName(); 037 public Long getId(); 038 public String getEmail(); 039 public void setIsNewInsert(Boolean isNew); 040 public Boolean getIsNewInsert(); 041 public String getBcryptedPassword(); 042 public <U extends IUser> U setBcryptedPassword(String password); 043 public String getResetToken(); 044 public <U extends IUser> U setResetToken(String token); 045 public Long getAliasForId(); 046 public <U extends IUser> U setAliasForId(Long id); 047 public Long getCreatedAt(); 048 public <U extends IUser> U setCreatedAt(Long createdAt); 049 050 051 @JsonView(RestrictedViews.Unrestricted.class) 052 default public Boolean isAuthorized() { 053 return !isAnon(); 054 } 055 056 057 058 @JsonIgnore 059 default public Boolean isAnon() { 060 if (!getApproved()) { 061 return true; 062 } 063 if (getRole() == null || Role.ANON.equals(getRole())) { 064 return true; 065 } else { 066 return false; 067 } 068 } 069 070 @JsonView(RestrictedViews.Owner.class) 071 default public Boolean isStaff() { 072 return isInRole(Role.STAFF); 073 } 074 075 @JsonIgnore 076 default public Boolean isInRole(Role role) { 077 if (Role.ANON.equals(role)) { 078 return true; 079 } 080 if (!getApproved()) { 081 return false; 082 } 083 if (getRole().getValue() >= role.getValue()) { 084 return true; 085 } 086 return false; 087 } 088 089 public Long getOrgId(); 090 public List<IGroup> getGroups(); 091 public String getSecret(); 092 public <U extends IUser> U setUsername(String username); 093 public <U extends IUser> U setDisplayName(String displayName); 094 public <U extends IUser> U setEmail(String email); 095 public Role getRole(); 096 public <U extends IUser> U setRole(Role role); 097 public <U extends IUser> U setOrgId(Long orgId); 098 public <U extends IUser> U setGroups(List<IGroup> groups); 099 public <U extends IUser> U setSecret(String secret); 100 public String getTimeZoneId(); 101 public <U extends IUser> U setTimeZoneId(String zoneId); 102 public boolean isPredefined(); 103 public <U extends IUser> U setPredefined(boolean predefined); 104 public String getEncryptionSecret(); 105 public <U extends IUser> U setEncryptionSecret(String secret); 106 107 public <U extends IUser> U setGivenName(String givenName); 108 public <U extends IUser> U setFamilyName(String familyName); 109 110 public Boolean getApproved(); 111 public boolean getEmailVerified(); 112 public <U extends IUser> U setApproved(Boolean approved); 113 public <U extends IUser> U setEmailVerified(boolean verified); 114 public <U extends IUser> U setDisabled(boolean disabled); 115 116}