diff options
author | jan <jan@ruken.pw> | 2015-12-29 18:57:27 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2015-12-29 18:57:27 (UTC) |
commit | de1276a29e9bc6cf427a326d1bf41be22b195e7d (patch) | |
tree | 40e2baea60250b84e4c07089c12f44494d28d5be /charakterin.go | |
parent | bd88166988bb31ff82da847d1e69c907f5f53930 (diff) |
GetUserByID implementiert.
Diffstat (limited to 'charakterin.go')
-rw-r--r-- | charakterin.go | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/charakterin.go b/charakterin.go index 142484c..253e627 100644 --- a/charakterin.go +++ b/charakterin.go | |||
@@ -13,9 +13,9 @@ import ( | |||
13 | ) | 13 | ) |
14 | 14 | ||
15 | const ( | 15 | const ( |
16 | NoSuchUser = "pq: no_such_user" | 16 | NoSuchUser = "pq: no_such_user" |
17 | InvalidPassword = "pq: invalid_password" | 17 | InvalidPassword = "pq: invalid_password" |
18 | UsernameTaken = "pq: username_taken" | 18 | UsernameTaken = "pq: username_taken" |
19 | EmailAlreadyRegistered = "pq: email_already_registered" | 19 | EmailAlreadyRegistered = "pq: email_already_registered" |
20 | ) | 20 | ) |
21 | 21 | ||
@@ -278,27 +278,22 @@ func (c *Charakterin) GetUserFromRequest(r *http.Request) (*User, error) { | |||
278 | } | 278 | } |
279 | 279 | ||
280 | var email, name string | 280 | var email, name string |
281 | var displayName *string | 281 | var displayName sql.NullString |
282 | var password []byte | 282 | var password []byte |
283 | var id int | 283 | var id int |
284 | var lastActivity time.Time | 284 | var lastActivity *time.Time |
285 | var isActive bool | 285 | var isActive bool |
286 | err = c.Database.QueryRow(`SELECT id, email, name, password, display_name, last_activity, is_active FROM login.get_user_by_session($1)`, cookie.Value).Scan(&id, &email, &name, &password, &displayName, &lastActivity, &isActive) | 286 | err = c.Database.QueryRow(`SELECT id, email, name, password, display_name, last_activity, is_active FROM login.get_user_by_session($1)`, cookie.Value).Scan(&id, &email, &name, &password, &displayName, &lastActivity, &isActive) |
287 | if err != nil { | 287 | if err != nil { |
288 | return nil, err | 288 | return nil, err |
289 | } | 289 | } |
290 | 290 | ||
291 | dspName := "" | ||
292 | if displayName != nil { | ||
293 | dspName = *displayName | ||
294 | } | ||
295 | |||
296 | user := &User{ | 291 | user := &User{ |
297 | id, | 292 | id, |
298 | name, | 293 | name, |
299 | email, | 294 | email, |
300 | password, | 295 | password, |
301 | dspName, | 296 | displayName, |
302 | lastActivity, | 297 | lastActivity, |
303 | isActive, | 298 | isActive, |
304 | } | 299 | } |
@@ -306,6 +301,16 @@ func (c *Charakterin) GetUserFromRequest(r *http.Request) (*User, error) { | |||
306 | return user, nil | 301 | return user, nil |
307 | } | 302 | } |
308 | 303 | ||
304 | // GetUserByID gibt den User mit der gegebenen ID zurück | ||
305 | func (c *Charakterin) GetUserByID(id int) (*User, error) { | ||
306 | user := &User{} | ||
307 | err := c.Database.QueryRow(`SELECT id, email, name, password, display_name, last_activity, is_active FROM login.users WHERE id = $1`, id).Scan(&user.ID, &user.EMail, &user.Name, &user.Password, &user.DisplayName, &user.LastActivity, &user.IsActive) | ||
308 | if err != nil { | ||
309 | return nil, err | ||
310 | } | ||
311 | return user, nil | ||
312 | } | ||
313 | |||
309 | // ConfirmEmail konfirmiert die email addresse mit der gegebenen confirm id. | 314 | // ConfirmEmail konfirmiert die email addresse mit der gegebenen confirm id. |
310 | func (c *Charakterin) ConfirmEmail(confirmId string) error { | 315 | func (c *Charakterin) ConfirmEmail(confirmId string) error { |
311 | var result string | 316 | var result string |