-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
162 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
api/externals/repository/sesstion_reset_password_repository.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"github.com/NUTFes/FinanSu/api/drivers/db" | ||
"fmt" | ||
) | ||
|
||
|
||
type sessionResetPasswordRepository struct { | ||
client db.Client | ||
} | ||
|
||
type SessionResetPasswordRepository interface { | ||
Create(context.Context, string, string, string) error | ||
Destroy(context.Context, string) error | ||
FindSessionByAccessToken(context.Context, string) *sql.Row | ||
DestroyByUserID(context.Context, string) error | ||
} | ||
|
||
func NewSessionResetPasswordRepository(client db.Client) SessionResetPasswordRepository { | ||
return &sessionResetPasswordRepository{client} | ||
} | ||
|
||
// 作成 | ||
func (r *sessionResetPasswordRepository) Create(c context.Context, authID string, userID string, accessToken string) error { | ||
query := "insert into session_reset_password (auth_id, user_id, access_token) values (" + authID + ", " + userID + ", '" + accessToken + "')" | ||
_, err := r.client.DB().ExecContext(c, query) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("\x1b[36m%s\n", query) | ||
return nil | ||
} | ||
|
||
// 削除 | ||
func (r *sessionResetPasswordRepository) Destroy(c context.Context, accessToken string) error { | ||
// access tokenで該当のsessionを削除 | ||
query := "delete from session_reset_password where access_token = '" + accessToken + "'" | ||
_, err := r.client.DB().ExecContext(c, query) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("\x1b[36m%s\n", query) | ||
return nil | ||
} | ||
|
||
// アクセストークンからセッションを取得 | ||
func (r *sessionResetPasswordRepository) FindSessionByAccessToken(c context.Context, accessToken string) *sql.Row { | ||
query := "select * from session_reset_password where access_token = '" + accessToken + "'" | ||
row := r.client.DB().QueryRowContext(c, query) | ||
fmt.Printf("\x1b[36m%s\n", query) | ||
return row | ||
} | ||
|
||
// user_idからsessionを削除する | ||
func (r *sessionResetPasswordRepository) DestroyByUserID(c context.Context, userID string) error { | ||
query := "delete from session_reset_password where user_id = " + userID | ||
_, err := r.client.DB().ExecContext(c, query) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("\x1b[36m%s\n", query) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use finansu_db; | ||
|
||
CREATE TABLE session_reset_password ( | ||
id int(10) unsigned not null unique auto_increment, | ||
auth_id int(10) not null, | ||
user_id int(10) not null, | ||
access_token varchar(255) not null, | ||
created_at datetime not null default current_timestamp, | ||
updated_at datetime not null default current_timestamp on update current_timestamp, | ||
PRIMARY KEY (auth_id) | ||
); |