-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
59 lines (53 loc) · 1.39 KB
/
profile.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"html/template"
"net/http"
"strconv"
)
type filetype struct {
Fname string
Sname string
About string
}
func fileform(w http.ResponseWriter, r *http.Request) {
chknon(w,r)
db := dbConnect()
htop(w, r)
var user User
user = isauth(w, r)
f := &filetype{Fname: user.fname, Sname: user.sname, About: user.about}
t, _ := template.ParseFiles("tmpl/fileform.html")
t.ExecuteTemplate(w,"form",f)
db.Close()
t, _ = template.ParseFiles("tmpl/footer.html")
t.ExecuteTemplate(w, "footer", nil)
}
func filesave(w http.ResponseWriter, r *http.Request) {
chknon(w,r)
var user User
user = isauth(w, r)
db = dbConnect()
result, err := db.Exec("update users set fname=?, sname=?, about=? where id=?", r.FormValue("fname"), r.FormValue("sname"), r.FormValue("about"), user.id)
if err != nil {
fmt.Println(err)
}
fmt.Println(result.RowsAffected())
db.Close()
http.Redirect(w, r, "/home", 301)
}
func fileview(w http.ResponseWriter, r *http.Request) {
htop(w, r)
var otheruser User
var oid = r.URL.Path[len("/fileview/"):]
i, err := strconv.Atoi(oid)
if err != nil {
fmt.Println(err)
}
otheruser = signbyid(i)
f := &filetype{Fname: otheruser.fname, Sname: otheruser.sname, About: otheruser.about}
t, _ := template.ParseFiles("tmpl/fileview.html")
t.ExecuteTemplate(w,"view",f)
t, _ = template.ParseFiles("tmpl/footer.html")
t.ExecuteTemplate(w, "footer", nil)
}