Documentation ¶
Index ¶
- Variables
- func AddNewPoll(pollTitle string, pollOptions []string, user User) (string, error)
- func CreateUserSession(w http.ResponseWriter, userID, username string) error
- func DeletePoll(pollID string) error
- func DestroyUserSession(w http.ResponseWriter, r *http.Request) error
- func GetPollVotes(pollID string) ([][]string, error)
- func GetVoteOptions(pollID string) ([]string, error)
- func HashPassword(password string) ([]byte, error)
- func PollAddUserVote(pollID, optionID, userID string) error
- func PollUpdate(poll Poll, newPollTitle string, newPollOptions [][]string) error
- func RegisterNewUser(username string, passwordHash []byte, email string) (string, error)
- func UserEmailCheck(email string) (bool, error)
- func UserExistCheck(username string) (bool, error)
- type LoginErrors
- type LoginUser
- type Poll
- type PollErrors
- type RegisterErrors
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrUserDoesNotExist = errors.New("This user does not exist")
ErrUserDoesNotExist error message if user does not exist in database
Functions ¶
func AddNewPoll ¶
AddNewPoll adds new poll to the database with pollTitle, pollOptions, Author returns: pollID, error
func CreateUserSession ¶
func CreateUserSession(w http.ResponseWriter, userID, username string) error
CreateUserSession creates session for current user, used for loggin user in. Currently Logged In user is defined with Cookie that contains jwt string with the relevant user data (id: user.id, username: user.username, loggedIn: bool)
func DeletePoll ¶
DeletePoll deletes poll with id = pollID and returns error if error occur
func DestroyUserSession ¶
func DestroyUserSession(w http.ResponseWriter, r *http.Request) error
DestroyUserSession destroys session by changing/emptying fields in currently active user cookie
func GetPollVotes ¶
GetPollVotes returns vote count for poll with id = pollID returns [[VoteOption1, count1], [VoteOption2, count2]]
func GetVoteOptions ¶
GetVoteOptions returns array of vote options that exist in db for chosen poll with id = pollID.
func HashPassword ¶
HashPassword hashes inserted users password
func PollAddUserVote ¶
PollAddUserVote checks if user already voted on the chosen poll
func PollUpdate ¶
PollUpdate handles poll updates with new data posted from poll_edit template
func RegisterNewUser ¶
RegisterNewUser creates new row in database for new user
func UserEmailCheck ¶
UserEmailCheck checks if email already exists in database false => email does not exist true => email does exist in db
func UserExistCheck ¶
UserExistCheck checks if user with username exists false => user does not exist true => user already in database error => an error happened
Types ¶
type LoginErrors ¶
type LoginErrors struct { Username string ErrorUsername string ErrorPassword string LoggedInUser User }
LoginErrors struct is used for displaying errors on login screen
type Poll ¶
type Poll struct { ID string Author string // author username Title string // title of the poll Time string Options [][]string // contains [[option title, option_id]] Votes [][]string // contains [[vote Option, vote count]] NumOfVotes string // for displaying number of all votes for the Poll //ErrorPostVote string // display error when user submits his vote LoggedInUser User // User struct for rendering different templates based on user login status Errors PollErrors // displaying error messages in new/edit poll templates }
Poll structure used to parse values from database
func GetFrontPageData ¶
GetFrontPageData returns array of polls based on chosen maxID(max poll id) and limit of results
func GetPollDetails ¶
GetPollDetails get's data about poll with id = pollID returned: {pollID, Title, Author, [pollOption, polloptionID]}
type PollErrors ¶
type PollErrors struct { Title string // upon error fill input with .Title TitleError string // display error when title is not suitable VoteOptions []string VoteOptionsError string // display error when user submitted < 2 vote options PostVoteError string // display error when user submits his vote EditPollError string // display error upon submitting edit poll form }
PollErrors are used to display /new/edit poll tempaltes
type RegisterErrors ¶
type RegisterErrors struct { Username string ErrorUsername string Email string ErrorEmail string Password string ErrorPassword string LoggedInUser User }
RegisterErrors stores error messages that will be displayed on register template if they occur
type User ¶
type User struct { ID string // user id Username string // users username LoggedIn bool // true => logged in, false => not logged in }
User struct used for creating tokens and parsing data from cookies
func GetUserData ¶
GetUserData gets userData from JWT token string and returns UserData (users.id, users.username) loggedIn (bool): true if token is formed correctly
false if token is forged or an error occured
func LoggedInUser ¶
LoggedInUser checks if GoVote(auth) cookie is present in client request and returns userStruct with {ID: user.id, Username: user.username, LoggedIn: true/false}