move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package auth_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/auth"
|
||||
)
|
||||
|
||||
func ExampleClient_UpdatePassword() {
|
||||
ctx := context.Background()
|
||||
client := telegram.NewClient(telegram.TestAppID, telegram.TestAppHash, telegram.Options{})
|
||||
if err := client.Run(ctx, func(ctx context.Context) error {
|
||||
// Updating password.
|
||||
if err := client.Auth().UpdatePassword(ctx, "new_password", auth.UpdatePasswordOptions{
|
||||
// Hint sets new password hint.
|
||||
Hint: "new password hint",
|
||||
// Password will be called if old password is requested by Telegram.
|
||||
//
|
||||
// If password was requested and Password is nil, auth.ErrPasswordNotProvided error will be returned.
|
||||
Password: func(ctx context.Context) (string, error) {
|
||||
return "old_password", nil
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleClient_ResetPassword() {
|
||||
ctx := context.Background()
|
||||
client := telegram.NewClient(telegram.TestAppID, telegram.TestAppHash, telegram.Options{})
|
||||
if err := client.Run(ctx, func(ctx context.Context) error {
|
||||
wait, err := client.Auth().ResetPassword(ctx)
|
||||
var waitErr *auth.ResetFailedWaitError
|
||||
switch {
|
||||
case errors.As(err, &waitErr):
|
||||
// Telegram requested wait until making new reset request.
|
||||
fmt.Printf("Wait until %s to reset password.\n", wait.String())
|
||||
case err != nil:
|
||||
return err
|
||||
}
|
||||
|
||||
// If returned time is zero, password was successfully reset.
|
||||
if wait.IsZero() {
|
||||
fmt.Println("Password was reset.")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("Password will be reset on %s.\n", wait.String())
|
||||
return nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user