Documentation
¶
Index ¶
- type AdminAuthService
- func (s *AdminAuthService) ChangePassword(userID, oldPassword, newPassword string) error
- func (s *AdminAuthService) CreatePushToken(adminID *string, token, deviceType, tokenType string) (*models.PushTokenModel, error)
- func (s *AdminAuthService) ForgotPassword(email string) error
- func (s *AdminAuthService) GetAdminByID(userID string) (*models.AdminModel, error)
- func (s *AdminAuthService) GetAdmins(request http.Request, search string) (paginate.Page, error)
- func (s *AdminAuthService) GetProfilePicture(userID string) (models.FileModel, error)
- func (s *AdminAuthService) GetUserByEmail(email string) (*models.AdminModel, error)
- func (s *AdminAuthService) GetUserByID(userID string) (*models.AdminModel, error)
- func (s *AdminAuthService) Login(usernameOrEmail, password string) (*models.AdminModel, error)
- func (s *AdminAuthService) Migrate() error
- func (s *AdminAuthService) Register(fullname, username, email, password string, isAdd bool) (*models.AdminModel, error)
- func (s *AdminAuthService) UpdateAdminByID(userID string, updatedData *models.AdminModel) error
- func (s *AdminAuthService) Verification(token, newPassword string) error
- func (s *AdminAuthService) VerificationEmail(token string) error
- type AuthService
- func (s *AuthService) ChangePassword(userID, oldPassword, newPassword string) error
- func (s *AuthService) CreatePushToken(userID *string, token, deviceType, tokenType string) (*models.PushTokenModel, error)
- func (s *AuthService) CreateUser(user *models.UserModel) (*models.UserModel, error)
- func (s *AuthService) DB() *gorm.DB
- func (s *AuthService) ForgotPassword(email string) error
- func (s *AuthService) GetCompanies(userID string) ([]models.CompanyModel, error)
- func (s *AuthService) GetTokenFromAdminID(userID string) ([]string, error)
- func (s *AuthService) GetTokenFromUserID(userID string) ([]string, error)
- func (s *AuthService) GetUserByEmail(email string) bool
- func (s *AuthService) GetUserByEmailOrPhone(emailOrPhone string) (*models.UserModel, error)
- func (s *AuthService) GetUserByID(userID string) (*models.UserModel, error)
- func (s *AuthService) GetUserByPhoneNumber(phone string) bool
- func (s *AuthService) GetUserDataByPhoneNumber(phoneNumber string) (*models.UserModel, error)
- func (s *AuthService) Login(usernameOrEmail, password string, checkVerified bool) (*models.UserModel, error)
- func (s *AuthService) Migrate() error
- func (s *AuthService) Register(fullname, username, email, password, phoneNumber string) (*models.UserModel, error)
- func (s *AuthService) UpdateAddress(userID string, address string) error
- func (s *AuthService) UpdateEmail(userID string, email string, verificationToken string, ...) error
- func (s *AuthService) UpdateLatLng(userID string, latitude, longitude float64) error
- func (s *AuthService) UpdateReferralCode(userID string, referralCode string) error
- func (s *AuthService) Verification(token, newPassword string) error
- func (s *AuthService) VerificationEmail(token string) error
- type RBACService
- func (s *RBACService) AddPermissionsToRole(roleID string, permissionNames []string) error
- func (s *RBACService) AssignPermissionToRole(roleName string, permissionName string) error
- func (s *RBACService) AssignPermissionToRoleID(id string, permissionName string) error
- func (s *RBACService) AssignRoleToAdmin(adminID string, roleName string) error
- func (s *RBACService) AssignRoleToUser(userID string, roleName string) error
- func (s *RBACService) CheckAdminPermission(adminID string, permissionNames []string) (bool, error)
- func (s *RBACService) CheckPermission(userID string, permissionNames []string) (bool, error)
- func (s *RBACService) CheckPermissionWithCompanyID(userID, companyID string, permissionNames []string) (bool, error)
- func (s *RBACService) CheckRoleExistsByName(name string, isAdmin bool) (bool, error)
- func (s *RBACService) CheckSuperAdminPermission(adminID string) (bool, error)
- func (s *RBACService) CreateRole(name string, isAdmin, isSuperAdmin, isMerchant bool, companyID *string) (*models.RoleModel, error)
- func (s *RBACService) DeleteRole(roleID string) error
- func (s *RBACService) GetAllPermissions() ([]models.PermissionModel, error)
- func (s *RBACService) GetAllRoles(request http.Request, search string) (paginate.Page, error)
- func (s *RBACService) GetRoleByID(roleID string) (*models.RoleModel, error)
- func (s *RBACService) GetRoleByName(name string, isAdmin bool) (*models.RoleModel, error)
- func (s *RBACService) GetRoleFromUser(userID string) (*models.RoleModel, error)
- func (s *RBACService) SetMode(mode string)
- func (s *RBACService) UpdateRole(roleID, name string, isAdmin, isSuperAdmin, isMerchant, isOwner bool) (*models.RoleModel, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdminAuthService ¶
type AdminAuthService struct {
// contains filtered or unexported fields
}
func NewAdminAuthService ¶
func NewAdminAuthService(erpContext *context.ERPContext) *AdminAuthService
func (*AdminAuthService) ChangePassword ¶
func (s *AdminAuthService) ChangePassword(userID, oldPassword, newPassword string) error
ChangePassword changes the password for a user.
It takes the user ID, old password, and new password as arguments.
It returns an error if the user is not found, the old password is invalid, or if there is a problem with the database.
func (*AdminAuthService) CreatePushToken ¶
func (s *AdminAuthService) CreatePushToken(adminID *string, token, deviceType, tokenType string) (*models.PushTokenModel, error)
CreatePushToken creates a new push token for an admin
It takes the admin ID, token, device type, and token type as arguments.
It returns a pointer to the created push token and an error.
func (*AdminAuthService) ForgotPassword ¶
func (s *AdminAuthService) ForgotPassword(email string) error
ForgotPassword sends a password reset email.
It takes the email as an argument.
It returns an error if the user is not found or if there is a problem with the database.
func (*AdminAuthService) GetAdminByID ¶
func (s *AdminAuthService) GetAdminByID(userID string) (*models.AdminModel, error)
GetAdminByID retrieves a user by their ID, preloading roles and permissions.
It returns the AdminModel with profile picture and permissions if found, otherwise an error.
func (*AdminAuthService) GetAdmins ¶
GetAdmins retrieves a list of users with pagination.
It takes a request and a search parameter as arguments.
The search parameter is used to search the users by full name, email, or username.
It returns a paginate.Page containing the list of AdminModel with profile picture.
func (*AdminAuthService) GetProfilePicture ¶
func (s *AdminAuthService) GetProfilePicture(userID string) (models.FileModel, error)
GetProfilePicture returns the profile picture of a user by their ID.
It takes the user ID as an argument.
It returns the FileModel of the profile picture if found, otherwise an error.
func (*AdminAuthService) GetUserByEmail ¶
func (s *AdminAuthService) GetUserByEmail(email string) (*models.AdminModel, error)
GetUserByEmail returns a user by their email
It takes the email as an argument.
It returns the UserModel if found, otherwise an error.
func (*AdminAuthService) GetUserByID ¶
func (s *AdminAuthService) GetUserByID(userID string) (*models.AdminModel, error)
GetUserByID returns a user by their ID
It takes the user ID as an argument.
It returns the UserModel if found, otherwise an error.
func (*AdminAuthService) Login ¶
func (s *AdminAuthService) Login(usernameOrEmail, password string) (*models.AdminModel, error)
Login logs in a user.
It takes the username or email and password as arguments.
It returns the logged in user if successful, otherwise an error.
func (*AdminAuthService) Migrate ¶
func (s *AdminAuthService) Migrate() error
Migrate runs the database migrations. It creates the tables for the admin models (AdminModel, RoleModel, and PermissionModel) if they do not exist yet.
func (*AdminAuthService) Register ¶
func (s *AdminAuthService) Register(fullname, username, email, password string, isAdd bool) (*models.AdminModel, error)
func (*AdminAuthService) UpdateAdminByID ¶
func (s *AdminAuthService) UpdateAdminByID(userID string, updatedData *models.AdminModel) error
UpdateAdminByID updates the data of a user by their ID.
It takes the user ID and data to be updated as arguments.
It returns an error if the user is not found or if there is an error saving the user.
func (*AdminAuthService) Verification ¶
func (s *AdminAuthService) Verification(token, newPassword string) error
func (*AdminAuthService) VerificationEmail ¶
func (s *AdminAuthService) VerificationEmail(token string) error
VerificationEmail verifies a user by their verification token
It takes the verification token as an argument.
It returns an error if the token is invalid, expired, or if there is an issue updating the user in the database.
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
AuthService is a service for managing user authentication.
It provides methods for registering, logging in, changing passwords, and verifying tokens.
func NewAuthService ¶
func NewAuthService(erpContext *context.ERPContext) *AuthService
NewAuthService creates a new instance of AuthService.
func (*AuthService) ChangePassword ¶
func (s *AuthService) ChangePassword(userID, oldPassword, newPassword string) error
ChangePassword changes the password for a user.
It takes the old password and new password as arguments.
func (*AuthService) CreatePushToken ¶
func (s *AuthService) CreatePushToken(userID *string, token, deviceType, tokenType string) (*models.PushTokenModel, error)
CreatePushToken creates a push token for a user.
It takes the user ID, token, device type, and token type as arguments.
It returns a pointer to the created push token and an error.
func (*AuthService) CreateUser ¶ added in v1.0.64
CreateUser creates a new user in the database.
It returns the created UserModel or an error if any occurs.
func (*AuthService) DB ¶
func (s *AuthService) DB() *gorm.DB
DB returns the underlying database connection.
func (*AuthService) ForgotPassword ¶
func (s *AuthService) ForgotPassword(email string) error
ForgotPassword sends a password reset email.
It takes the email as an argument.
func (*AuthService) GetCompanies ¶
func (s *AuthService) GetCompanies(userID string) ([]models.CompanyModel, error)
GetCompanies retrieves the companies of a user.
It takes the user ID as an argument.
It returns a slice of CompanyModel and an error.
func (*AuthService) GetTokenFromAdminID ¶
func (s *AuthService) GetTokenFromAdminID(userID string) ([]string, error)
GetTokenFromAdminID returns a slice of strings containing the push tokens of an admin
It takes the admin ID as an argument.
It returns a slice of strings containing the push tokens if found, otherwise an error.
func (*AuthService) GetTokenFromUserID ¶
func (s *AuthService) GetTokenFromUserID(userID string) ([]string, error)
GetTokenFromUserID retrieves the push tokens of a user.
It takes the user ID as an argument.
It returns a slice of strings and an error.
func (*AuthService) GetUserByEmail ¶
func (s *AuthService) GetUserByEmail(email string) bool
GetUserByEmail checks if a user exists by their email.
It returns true if found, otherwise false.
func (*AuthService) GetUserByEmailOrPhone ¶
func (s *AuthService) GetUserByEmailOrPhone(emailOrPhone string) (*models.UserModel, error)
GetUserByEmailOrPhone retrieves a user by their email or phone number.
It returns the UserModel if found, otherwise an error.
func (*AuthService) GetUserByID ¶
func (s *AuthService) GetUserByID(userID string) (*models.UserModel, error)
GetUserByID retrieves a user by their ID, preloading roles and permissions.
It returns the UserModel with profile picture and permissions if found, otherwise an error.
func (*AuthService) GetUserByPhoneNumber ¶
func (s *AuthService) GetUserByPhoneNumber(phone string) bool
GetUserByPhoneNumber checks if a user exists by their phone number.
It returns true if found, otherwise false.
func (*AuthService) GetUserDataByPhoneNumber ¶
func (s *AuthService) GetUserDataByPhoneNumber(phoneNumber string) (*models.UserModel, error)
GetUserDataByPhoneNumber retrieves a user by their phone number.
It returns the UserModel if found, otherwise an error.
func (*AuthService) Login ¶
func (s *AuthService) Login(usernameOrEmail, password string, checkVerified bool) (*models.UserModel, error)
Login logs in a user.
It takes the username or email and password as arguments.
func (*AuthService) Migrate ¶
func (s *AuthService) Migrate() error
Migrate runs the database migrations.
func (*AuthService) Register ¶
func (s *AuthService) Register(fullname, username, email, password, phoneNumber string) (*models.UserModel, error)
Register creates a new user.
It takes the full name, username, email, password, and phone number as arguments.
func (*AuthService) UpdateAddress ¶
func (s *AuthService) UpdateAddress(userID string, address string) error
UpdateAddress updates the address of a user.
It takes the user ID and address as arguments.
It returns an error if there is an error saving the user.
func (*AuthService) UpdateEmail ¶
func (s *AuthService) UpdateEmail(userID string, email string, verificationToken string, verificationExpiredAt time.Time) error
UpdateEmail updates the email of a user.
It takes the user ID, email, verification token, and verification expired at as arguments.
It returns an error if the user is already verified or if there is an error saving the user.
func (*AuthService) UpdateLatLng ¶
func (s *AuthService) UpdateLatLng(userID string, latitude, longitude float64) error
UpdateLatLng updates the latitude and longitude of a user.
It takes the user ID, latitude, and longitude as arguments.
It returns an error if there is an error saving the user.
func (*AuthService) UpdateReferralCode ¶
func (s *AuthService) UpdateReferralCode(userID string, referralCode string) error
UpdateReferralCode updates the referral code of a user.
It takes the user ID and referral code as arguments.
It returns an error if the user is already verified or if there is an error saving the user.
func (*AuthService) Verification ¶
func (s *AuthService) Verification(token, newPassword string) error
Verification memverifikasi token reset password
func (*AuthService) VerificationEmail ¶
func (s *AuthService) VerificationEmail(token string) error
VerificationEmail memverifikasi token reset password
It takes the token as an argument.
It returns an error if the token is invalid or has expired.
type RBACService ¶
type RBACService struct {
// contains filtered or unexported fields
}
func NewRBACService ¶
func NewRBACService(erpContext *context.ERPContext) *RBACService
func (*RBACService) AddPermissionsToRole ¶
func (s *RBACService) AddPermissionsToRole(roleID string, permissionNames []string) error
AddPermissionsToRole menambahkan beberapa izin ke peran
func (*RBACService) AssignPermissionToRole ¶
func (s *RBACService) AssignPermissionToRole(roleName string, permissionName string) error
AssignPermissionToRole menetapkan izin ke peran
func (*RBACService) AssignPermissionToRoleID ¶
func (s *RBACService) AssignPermissionToRoleID(id string, permissionName string) error
func (*RBACService) AssignRoleToAdmin ¶ added in v1.0.56
func (s *RBACService) AssignRoleToAdmin(adminID string, roleName string) error
AssignRoleToAdmin menetapkan peran ke admin
func (*RBACService) AssignRoleToUser ¶
func (s *RBACService) AssignRoleToUser(userID string, roleName string) error
AssignRoleToUser menetapkan peran ke pengguna
func (*RBACService) CheckAdminPermission ¶
func (s *RBACService) CheckAdminPermission(adminID string, permissionNames []string) (bool, error)
CheckPermission memeriksa apakah pengguna memiliki izin tertentu
func (*RBACService) CheckPermission ¶
func (s *RBACService) CheckPermission(userID string, permissionNames []string) (bool, error)
CheckPermission memeriksa apakah pengguna memiliki izin tertentu
func (*RBACService) CheckPermissionWithCompanyID ¶
func (s *RBACService) CheckPermissionWithCompanyID(userID, companyID string, permissionNames []string) (bool, error)
func (*RBACService) CheckRoleExistsByName ¶
func (s *RBACService) CheckRoleExistsByName(name string, isAdmin bool) (bool, error)
CheckRoleExistsByName memeriksa apakah peran dengan nama tertentu ada
func (*RBACService) CheckSuperAdminPermission ¶
func (s *RBACService) CheckSuperAdminPermission(adminID string) (bool, error)
func (*RBACService) CreateRole ¶
func (s *RBACService) CreateRole(name string, isAdmin, isSuperAdmin, isMerchant bool, companyID *string) (*models.RoleModel, error)
CreateRole membuat peran baru
func (*RBACService) DeleteRole ¶
func (s *RBACService) DeleteRole(roleID string) error
DeleteRole menghapus peran berdasarkan ID
func (*RBACService) GetAllPermissions ¶
func (s *RBACService) GetAllPermissions() ([]models.PermissionModel, error)
GetAllPermissions mengambil semua izin
func (*RBACService) GetAllRoles ¶
GetAllRoles mengambil semua peran
func (*RBACService) GetRoleByID ¶
func (s *RBACService) GetRoleByID(roleID string) (*models.RoleModel, error)
GetRoleByID mengambil peran berdasarkan ID
func (*RBACService) GetRoleByName ¶
GetRoleByName mengambil peran berdasarkan nama
func (*RBACService) GetRoleFromUser ¶ added in v1.0.56
func (s *RBACService) GetRoleFromUser(userID string) (*models.RoleModel, error)
GetRoleFromUser mengambil peran berdasarkan user
func (*RBACService) SetMode ¶
func (s *RBACService) SetMode(mode string)
func (*RBACService) UpdateRole ¶
func (s *RBACService) UpdateRole(roleID, name string, isAdmin, isSuperAdmin, isMerchant, isOwner bool) (*models.RoleModel, error)
UpdateRole memperbarui informasi peran berdasarkan ID