forked from tanitall/memo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini.go
42 lines (40 loc) · 1.25 KB
/
mini.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package profile
import (
"github.com/jchavannes/jgo/jerr"
"github.com/jchavannes/jgo/web"
"github.com/memocash/memo/app/auth"
"github.com/memocash/memo/app/bitcoin/wallet"
"github.com/memocash/memo/app/db"
"github.com/memocash/memo/app/profile"
"github.com/memocash/memo/app/res"
"net/http"
)
var miniRoute = web.Route{
Pattern: res.UrlProfileMini + "/" + urlAddress.UrlPart(),
Handler: func(r *web.Response) {
addressString := r.Request.GetUrlNamedQueryVariable(urlAddress.Id)
address := wallet.GetAddressFromString(addressString)
pkHash := address.GetScriptAddress()
var userPkHash []byte
if auth.IsLoggedIn(r.Session.CookieId) {
user, err := auth.GetSessionUser(r.Session.CookieId)
if err != nil {
r.Error(jerr.Get("error getting session user", err), http.StatusInternalServerError)
return
}
key, err := db.GetKeyForUser(user.Id)
if err != nil {
r.Error(jerr.Get("error getting key for user", err), http.StatusInternalServerError)
return
}
userPkHash = key.PkHash
}
pf, err := profile.GetBasicProfile(pkHash, userPkHash)
if err != nil {
r.Error(jerr.Get("error getting profile for hash", err), http.StatusInternalServerError)
return
}
r.Helper["Profile"] = pf
r.RenderTemplate(res.UrlProfileMini)
},
}