Uploading an avatar picture
In the third and final approach of uploading a picture, we will look at how to allow users to upload an image from their local hard drive to use as their profile picture when chatting. The file will then be served to the browsers via a URL. We will need a way to associate a file with a particular user to ensure that we associate the right picture with the corresponding messages.
User identification
In order to uniquely identify our users, we are going to copy Gravatar's approach by hashing their e-mail address and using the resulting string as an identifier. We will store the user ID in the cookie along with the rest of the user-specific data. This will actually have the added benefit of removing the inefficiency associated with continuous hashing from GravatarAuth
.
In auth.go
, replace the code that creates the authCookieValue
object with the following code:
m := md5.New() io.WriteString(m, strings.ToLower(user.Email())) userId := fmt.Sprintf("%x"...