Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
rename all 'signin' to 'login'
Browse files Browse the repository at this point in the history
  • Loading branch information
dimboknv committed Mar 18, 2022
1 parent f189b7b commit 77b82fd
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -83,7 +83,6 @@ services:
- REPORTER_INTERVAL=50m
- REPORTER_INTERVAL_MAX_REPORTS=20
- REPORTER_MESSAGE=The channel undermines the integrity of the Ukrainian state. Spreading fake news, misleading people. There are a lot of posts with threats against Ukrainians and Ukrainian soldiers. Block him ASAP

volumes:
- <PUBLIC KEY FILE>:/app/publicKey
- <DATABASE FOLDER>::/app/db
Expand Down
7 changes: 4 additions & 3 deletions app/bot/handle_commands.go
Expand Up @@ -2,6 +2,7 @@ package bot

import (
"context"
"fmt"

"github.com/dimboknv/tg-stand-with-ukraine/app/store"

Expand All @@ -16,10 +17,10 @@ func (b *Bot) handleStartCommand(ctx context.Context, user store.User, chatID in
if err := b.sendWelcomeMsg(chatID); err != nil {
return err
}
return b.sendMsg(chatID, "Use /login command for add telegram clients")
return b.sendMsg(chatID, fmt.Sprintf("Use /%s command for add telegram clients", store.LogInCommand))
}

func (b *Bot) handleLoginCommand(ctx context.Context, user store.User, chatID int64, u tgbotapi.Update) error {
func (b *Bot) handleLogInCommand(ctx context.Context, user store.User, chatID int64, u tgbotapi.Update) error {
if user.Phone != "" {
user.Chats[chatID].Navigation = store.PhoneNavigation
return b.sendInlineKbWithPhone(user, chatID, user.Phone)
Expand All @@ -30,7 +31,7 @@ func (b *Bot) handleLoginCommand(ctx context.Context, user store.User, chatID in
return err
}

msg := tgbotapi.NewMessage(chatID, "Before SignIn you have to share phone number")
msg := tgbotapi.NewMessage(chatID, "Before log in you have to share phone number")
msg.ReplyMarkup = tgbotapi.NewReplyKeyboard(
tgbotapi.NewKeyboardButtonRow(
tgbotapi.NewKeyboardButtonContact("\xF0\x9F\x93\x9E Send phone"),
Expand Down
8 changes: 4 additions & 4 deletions app/bot/handle_navigation.go
Expand Up @@ -70,7 +70,7 @@ func parsePhone(txt string) (phone string, err error) {
if len(phone) != 13 {
return "", &userError{
Err: errors.Errorf("invalid phone number: %q", phone),
UserMsg: "Invalid phone number. Try again /login",
UserMsg: fmt.Sprintf("Invalid phone number. Try again /%s", store.LogInCommand),
}
}
return phone, nil
Expand All @@ -85,7 +85,7 @@ func (b *Bot) phoneNavigation(ctx context.Context, user store.User, chatID int64
txt, navigation := "Send pass code", store.CodeNavigation
if phone == user.Phone {
// nolint
txt = `You are trying to sign-in with you current account and telegram does not allow to send secure code in one message to anyone.
txt = `You are trying to log in with you current account and telegram does not allow to send secure code in one message to anyone.
Please, split secure code and send by 2 messages. For example, you got "12345" then send 1-th message with text "123" and 2-th message with "45". You can split code in any combination except full code.
Expand Down Expand Up @@ -157,7 +157,7 @@ func (b *Bot) startHubAuth(ctx context.Context, user store.User, chatID int64, c
if err := b.deleteChatMessages(chatID, user.Chats[chatID].DeleteMsgIDs...); err != nil {
return err
}
msg := fmt.Sprintf("Thanks! %q is successfully sign in!", user.Chats[chatID].AuthPhone)
msg := fmt.Sprintf("Thanks! %q is successfully logged in!", user.Chats[chatID].AuthPhone)
user.Chats[chatID].Navigation = store.UserNavigation
user.Chats[chatID].DeleteMsgIDs = nil
if req2fa {
Expand Down Expand Up @@ -187,7 +187,7 @@ func (b *Bot) pass2faNavigation(ctx context.Context, user store.User, chatID int
UserMsg: "Sorry, can't verify 2FA password",
}
}
return b.sendMsg(chatID, fmt.Sprintf("Thanks! %q is successfully sign in!", user.Chats[chatID].AuthPhone))
return b.sendMsg(chatID, fmt.Sprintf("Thanks! %q is successfully logged in!", user.Chats[chatID].AuthPhone))
}

func (b *Bot) userNavigation(ctx context.Context, user store.User, chatID int64, u tgbotapi.Update) error {
Expand Down
2 changes: 1 addition & 1 deletion app/bot/handlers.go
Expand Up @@ -22,7 +22,7 @@ func (b *Bot) registerNavigationHandlers() {

b.cmdHandlers = map[string]handler{
store.StartCommand: b.handleStartCommand,
store.LoginCommand: b.handleLoginCommand,
store.LogInCommand: b.handleLogInCommand,
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/hub/actions.go
Expand Up @@ -50,13 +50,13 @@ func updateIsAuthorized(db store.Store) action {
}
}

func updateSignInAt(db store.Store) action {
func updateLogInAt(db store.Store) action {
return func(ctx context.Context, client *telegram.Client, user store.User, phone string) error {
u, err := db.GetUser(user.ID)
if err != nil {
return err
}
u.Clients[phone].SignInAt = time.Now()
u.Clients[phone].LogInAt = time.Now()
return db.PutUser(u)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/hub/hub.go
Expand Up @@ -150,7 +150,7 @@ func (h *Hub) AuthCode(ctx context.Context, user store.User, phone, code string)
return false, err
}
if authorized {
return false, chain(updateSignInAt(h.db), updateIsAuthorized(h.db))(ctx, client, user, phone)
return false, chain(updateLogInAt(h.db), updateIsAuthorized(h.db))(ctx, client, user, phone)
}

_, signInErr := client.Auth().SignIn(ctx, phone, code, codeHash)
Expand All @@ -169,7 +169,7 @@ func (h *Hub) AuthPass2FA(ctx context.Context, user store.User, phone, pass2fa s
if _, err := client.Auth().Password(ctx, pass2fa); err != nil {
return errors.Wrap(err, "invalid 2fa")
}
return chain(updateSignInAt(h.db), updateIsAuthorized(h.db))(ctx, client, user, phone)
return chain(updateLogInAt(h.db), updateIsAuthorized(h.db))(ctx, client, user, phone)
}

func (h *Hub) newClient(user store.User, phone string) *telegram.Client {
Expand Down
6 changes: 3 additions & 3 deletions app/store/user.go
Expand Up @@ -5,8 +5,8 @@ import "time"
type Navigation int

const (
LoginCommand = "login"
LogoutCommand = "logout"
LogInCommand = "login"
LogOutCommand = "logout"
StartCommand = "start"

WelcomeNavigation Navigation = iota
Expand Down Expand Up @@ -37,7 +37,7 @@ type Chat struct {

type Client struct {
LastConnectionAt time.Time
SignInAt time.Time
LogInAt time.Time
SentReports map[string]Report // [url]report
Phone string
Session []byte
Expand Down

0 comments on commit 77b82fd

Please sign in to comment.