summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-30 23:46:32 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-30 23:46:32 +0200
commita007e53b037a08ce34efd0b936dfa03127c2b7d1 (patch)
tree3faf168750ebb86ea09d893258cd3c1d6c20dd4f
parentd4fe97a9a5437d71a5a29f413ba7be6efe5f7da3 (diff)
downloadmailremind-a007e53b037a08ce34efd0b936dfa03127c2b7d1.tar.gz
mailremind-a007e53b037a08ce34efd0b936dfa03127c2b7d1.tar.bz2
mailremind-a007e53b037a08ce34efd0b936dfa03127c2b7d1.zip
Added {,Set}Location to model
-rw-r--r--model/dbmodel.go3
-rw-r--r--model/mysql/queries.go2
-rw-r--r--model/mysql/users.go26
3 files changed, 23 insertions, 8 deletions
diff --git a/model/dbmodel.go b/model/dbmodel.go
index cc4a6d7..2889908 100644
--- a/model/dbmodel.go
+++ b/model/dbmodel.go
@@ -34,6 +34,9 @@ type User interface {
ActivationCode() string
SetActivationCode(string) error
+ Location() *time.Location
+ SetLocation(*time.Location) error
+
Delete() error
}
diff --git a/model/mysql/queries.go b/model/mysql/queries.go
index 7d7b860..e579df7 100644
--- a/model/mysql/queries.go
+++ b/model/mysql/queries.go
@@ -20,6 +20,7 @@ const (
qInsertJob
qInsertUser
qSetChronos
+ qSetLocation
qEnd
)
@@ -48,4 +49,5 @@ var queries = map[int]string{
qInsertJob: "INSERT INTO `jobs` (`user`, `subject`, `content`, `next`, `chronos`) VALUES (?, ?, ?, ?, ?)",
qInsertUser: "INSERT INTO `users` (`email`, `passwd`, `location`, `active`, `activationcode`, `added`) VALUES (?, ?, ?, ?, ?, ?)",
qSetChronos: "UPDATE `jobs` SET `chronos` = ? WHERE `id` = ?",
+ qSetLocation: "UPDATE `users` SET `location` = ? WHERE `id` = ?",
}
diff --git a/model/mysql/users.go b/model/mysql/users.go
index 017d34f..f4e3c1c 100644
--- a/model/mysql/users.go
+++ b/model/mysql/users.go
@@ -62,16 +62,17 @@ func (con *MySQLDBCon) UserByMail(email string) (model.User, error) {
return userFromSQL(con, row)
}
-func (u *User) ID() model.DBID { return u.id }
-func (u *User) Email() string { return u.email }
-func (u *User) PWHash() []byte { return []byte(u.passwd) }
-func (u *User) Active() bool { return u.active }
-func (u *User) ActivationCode() string { return u.acCode }
+func (u *User) ID() model.DBID { return u.id }
+func (u *User) Email() string { return u.email }
+func (u *User) PWHash() []byte { return []byte(u.passwd) }
+func (u *User) Active() bool { return u.active }
+func (u *User) ActivationCode() string { return u.acCode }
+func (u *User) Location() *time.Location { return u.location }
func (u *User) SetPWHash(_pwhash []byte) error {
pwhash := string(_pwhash)
- if _, err := u.con.stmt[qSetPWHash].Query(pwhash, uint64(u.id)); err != nil {
+ if _, err := u.con.stmt[qSetPWHash].Exec(pwhash, uint64(u.id)); err != nil {
return err
}
@@ -80,7 +81,7 @@ func (u *User) SetPWHash(_pwhash []byte) error {
}
func (u *User) SetActive(b bool) error {
- if _, err := u.con.stmt[qSetActive].Query(b2i(b), uint64(u.id)); err != nil {
+ if _, err := u.con.stmt[qSetActive].Exec(b2i(b), uint64(u.id)); err != nil {
return err
}
@@ -89,7 +90,7 @@ func (u *User) SetActive(b bool) error {
}
func (u *User) SetActivationCode(c string) error {
- if _, err := u.con.stmt[qSetAcCode].Query(c, uint64(u.id)); err != nil {
+ if _, err := u.con.stmt[qSetAcCode].Exec(c, uint64(u.id)); err != nil {
return err
}
@@ -97,6 +98,15 @@ func (u *User) SetActivationCode(c string) error {
return nil
}
+func (u *User) SetLocation(loc *time.Location) error {
+ if _, err := u.con.stmt[qSetLocation].Exec(loc.String(), uint64(u.id)); err != nil {
+ return err
+ }
+
+ u.location = loc
+ return nil
+}
+
func (u *User) Delete() error {
tx, err := u.con.con.Begin()
if err != nil {