mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00

* chore: update auth * chore: password changes * chore: make changes in oss code * chore: login * chore: get to a running state * fix: migration inital commit * fix: signoz cloud intgtn tests * fix: minor fixes * chore: sso code fixed with org domain * fix: tests * fix: ee auth api's * fix: changes in name * fix: return user in login api * fix: address comments * fix: validate password * fix: handle get domain by email properly * fix: move authomain to usermodule * fix: use displayname instead of hname * fix: rename back endpoints * fix: update telemetry * fix: correct errors * fix: test and fix the invite endpoints * fix: delete all things related to user in store * fix: address issues * fix: ee delete invite * fix: rename func * fix: update user and update role * fix: update role * fix: login and invite changes * fix: return org name in users response * fix: update user role * fix: nil check * fix: getinvite and update role * fix: sso * fix: getinvite use sso ctx * fix: use correct sourceurl * fix: getsourceurl from req payload * fix: update created_at * fix: fix reset password * fix: sso signup and token password change * fix: don't delete last admin * fix: reset password and migration * fix: migration * fix: reset password for sso users * fix: clean up invite * fix: migration * fix: update claims and store code * fix: use correct error * fix: proper nil checks * fix: make migration multitenant * fix: address comments * fix: minor fixes * fix: test * fix: rename reset password --------- Co-authored-by: Vikrant Gupta <vikrant@signoz.io>
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SigNoz/signoz/pkg/alertmanager"
|
|
"github.com/SigNoz/signoz/pkg/modules/organization"
|
|
"github.com/SigNoz/signoz/pkg/modules/quickfilter"
|
|
"github.com/SigNoz/signoz/pkg/modules/user"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/model"
|
|
"github.com/SigNoz/signoz/pkg/types"
|
|
)
|
|
|
|
func RegisterOrgAndFirstUser(ctx context.Context, req *types.PostableRegisterOrgAndAdmin, organizationModule organization.Module, userModule user.Module) (*types.User, *model.ApiError) {
|
|
if req.Email == "" {
|
|
return nil, model.BadRequest(model.ErrEmailRequired{})
|
|
}
|
|
|
|
if req.Password == "" {
|
|
return nil, model.BadRequest(model.ErrPasswordRequired{})
|
|
}
|
|
|
|
organization := types.NewOrganization(req.OrgDisplayName)
|
|
err := organizationModule.Create(ctx, organization)
|
|
if err != nil {
|
|
return nil, model.InternalError(err)
|
|
}
|
|
|
|
user, err := types.NewUser(req.Name, req.Email, types.RoleAdmin.String(), organization.ID.StringValue())
|
|
if err != nil {
|
|
return nil, model.InternalError(err)
|
|
}
|
|
|
|
password, err := types.NewFactorPassword(req.Password)
|
|
if err != nil {
|
|
return nil, model.InternalError(err)
|
|
}
|
|
|
|
user, err = userModule.CreateUserWithPassword(ctx, user, password)
|
|
if err != nil {
|
|
return nil, model.InternalError(err)
|
|
}
|
|
|
|
return user, nil
|
|
}
|
|
|
|
// First user registration
|
|
func Register(ctx context.Context, req *types.PostableRegisterOrgAndAdmin, alertmanager alertmanager.Alertmanager, organizationModule organization.Module, userModule user.Module, quickfiltermodule quickfilter.Usecase) (*types.User, *model.ApiError) {
|
|
user, err := RegisterOrgAndFirstUser(ctx, req, organizationModule, userModule)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := alertmanager.SetDefaultConfig(ctx, user.OrgID); err != nil {
|
|
return nil, model.InternalError(err)
|
|
}
|
|
|
|
if err := quickfiltermodule.SetDefaultConfig(ctx, valuer.MustNewUUID(user.OrgID)); err != nil {
|
|
return nil, model.InternalError(err)
|
|
}
|
|
|
|
return user, nil
|
|
}
|