models

package
v0.0.0-...-909c4d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2020 License: GPL-3.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JwtAuthentication = func(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

		notAuth := []string{"/api/health", "/api/user/new", "/api/user/login", "/api/global-settings"}
		requestPath := r.URL.Path

		for _, value := range notAuth {

			if value == requestPath {
				next.ServeHTTP(w, r)
				return
			}
		}

		if strings.HasPrefix(r.URL.Path, "/api/images") {
			next.ServeHTTP(w, r)
			return
		}

		response := make(map[string]interface{})
		tokenHeader := r.Header.Get("Authorization")

		if tokenHeader == "" {
			response = utils.Message(false, "Missing auth token")
			w.WriteHeader(http.StatusForbidden)
			utils.Respond(w, response)
			return
		}

		tk := &Token{}

		token, err := jwt.ParseWithClaims(tokenHeader, tk, func(token *jwt.Token) (interface{}, error) {
			return []byte(os.Getenv("TOKEN_SECRET")), nil
		})

		if err != nil {
			response = utils.Message(false, "Malformed authentication token")
			w.WriteHeader(http.StatusForbidden)
			utils.Respond(w, response)
			return
		}

		if !token.Valid {
			response = utils.Message(false, "Token is not valid.")
			w.WriteHeader(http.StatusForbidden)
			utils.Respond(w, response)
			return
		}

		ctx := context.WithValue(r.Context(), "user", tk.UserId)
		r = r.WithContext(ctx)
		next.ServeHTTP(w, r)
	})
}

Functions

func CreateRequest

func CreateRequest(requestType string, initiatorId uint, targetId uint) map[string]interface{}

func GetDB

func GetDB() *gorm.DB

func GetGlobalSettings

func GetGlobalSettings() map[string]interface{}

func HandleFormingRequest

func HandleFormingRequest(userId uint, requesterId uint, accept bool) map[string]interface{}

func HandleJoiningRequest

func HandleJoiningRequest(groupId uint, userId uint, accept bool) map[string]interface{}

func InitializeGlobalSettings

func InitializeGlobalSettings()

func IsAdmin

func IsAdmin(userId uint) bool

func Login

func Login(email, password string) map[string]interface{}

func RequestExists

func RequestExists(request Request) bool

func SaveGlobalSettings

func SaveGlobalSettings(settings map[string]interface{}) map[string]interface{}

Types

type Account

type Account struct {
	gorm.Model
	Email           string `json:"email"`
	Password        string `json:"password"`
	Name            string `json:"name"`
	Tagline         string `json:"tagline"`
	Degree          string `json:"degree"`
	Year            string `json:"year"`
	Token           string `json:"token";gorm:"-"`
	Role            string `json:"role"`
	GroupId         *uint  `json:"groupId"`
	ImageUrl        string `json:"imageUrl"`
	Bio             string `json:"bio"`
	IsVerified      *bool  `json:"isVerified"`
	RejectionReason string `json:"rejectionReason"`
}

func GetAllUsers

func GetAllUsers(hidePassword bool) []Account

func GetUser

func GetUser(userId uint, hidePassword bool) *Account

func (*Account) Create

func (account *Account) Create() map[string]interface{}

func (*Account) Delete

func (account *Account) Delete()

func (*Account) GetPublicInfo

func (account *Account) GetPublicInfo() AccountPublic

func (*Account) SetGroupId

func (account *Account) SetGroupId(groupId uint)

func (*Account) Validate

func (account *Account) Validate() (map[string]interface{}, bool)

type AccountPublic

type AccountPublic struct {
	Name       string `json:"name"`
	Tagline    string `json:"tagline"`
	Degree     string `json:"degree"`
	Year       string `json:"year"`
	UserId     uint   `json:"userId"`
	ImageUrl   string `json:"imageUrl"`
	Bio        string `json:"bio"`
	IsVerified *bool  `json:"isVerified"`
}

type Activity

type Activity struct {
	gorm.Model
	GroupId         uint           `json:"groupId"`
	TemplateId      *uint          `json:"templateId"`
	Name            string         `json:"name"`
	Points          uint           `json:"points"`
	Time            string         `json:"time"`
	Participants    pq.Int64Array  `json:"participants" gorm:"type:int[]"`
	Images          pq.StringArray `json:"images" gorm:"type:varchar(100)[]"`
	IsVerified      *bool          `json:"isVerified"`
	RejectionReason string         `json:"rejectionReason"`
}

func GetActivity

func GetActivity(id uint) *Activity

type AuthResponse

type AuthResponse struct {
	Name     string `json:"name"`
	ImageUrl string `json:"imageUrl"`
	Token    string `json:"token"`
	Role     string `json:"role"`
}

type AvailableMentor

type AvailableMentor struct {
	Name             string `json:"name"`
	UserId           uint   `json:"userId"`
	ImageUrl         string `json:"imageUrl"`
	HasRequestedYou  bool   `json:"hasRequestedYou"`
	YouHaveRequested bool   `json:"youHaveRequested"`
}

func GetFreeMentors

func GetFreeMentors(userId uint) []AvailableMentor

type GlobalSetting

type GlobalSetting struct {
	gorm.Model
	Key       string
	Value     int
	IsBoolean bool
}

func (*GlobalSetting) GetValue

func (globalSetting *GlobalSetting) GetValue() interface{}

type Group

type Group struct {
	gorm.Model
	Title       string `json:"title"`
	Tagline     string `json:"tagline"`
	Description string `json:"description"`
}

func GetGroup

func GetGroup(id uint) *Group

func (*Group) Create

func (group *Group) Create(mentors []uint) map[string]interface{}

func (*Group) GetDetails

func (group *Group) GetDetails() GroupDetails

func (*Group) GetMentors

func (group *Group) GetMentors() GroupWithMentors

func (*Group) Validate

func (group *Group) Validate(mentors []uint) (map[string]interface{}, bool)

type GroupDetails

type GroupDetails struct {
	Title       string          `json:"title"`
	Tagline     string          `json:"tagline"`
	Description string          `json:"description"`
	Mentors     []AccountPublic `json:"mentors"`
	Mentees     []AccountPublic `json:"mentees"`
	Requests    []AccountPublic `json:"requests"`
	Activities  []Activity      `json:"activities"`
}

func GetGroupDetails

func GetGroupDetails(groupId uint) *GroupDetails

type GroupWithMentors

type GroupWithMentors struct {
	Id          uint            `json:"id"`
	Title       string          `json:"title"`
	Tagline     string          `json:"tagline"`
	Description string          `json:"description"`
	Mentors     []AccountPublic `json:"mentors"`
}

func GetGroups

func GetGroups() []GroupWithMentors

type Request

type Request struct {
	gorm.Model
	Type      string
	Initiator uint // Id of the requester
	Target    uint // Id of the target (group for joining, user for group creating, etc)
}

type TemplateActivity

type TemplateActivity struct {
	gorm.Model
	Name                 string `json:"name"`
	Points               uint   `json:"points"`
	RequiredParticipants uint   `json:"requiredParticipants"`
}

func GetTemplateActivities

func GetTemplateActivities() []TemplateActivity

func GetTemplateActivity

func GetTemplateActivity(id uint) *TemplateActivity

func (*TemplateActivity) Save

func (templateActivity *TemplateActivity) Save()

type Token

type Token struct {
	UserId uint
	jwt.StandardClaims
}

type UnverifiedActivity

type UnverifiedActivity struct {
	Name      string `json:"name"`
	ID        uint
	GroupName string `json:"groupName"`
}

func GetUnverifiedActivities

func GetUnverifiedActivities() []UnverifiedActivity

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL