mirror of
https://github.com/documize/community.git
synced 2025-07-21 22:29:41 +02:00
major package structure refactoring
This commit is contained in:
parent
7b8cec9a6c
commit
cf58f8164d
73 changed files with 549 additions and 389 deletions
|
@ -18,6 +18,8 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"obiwan/utility"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/documize/community/core/api/entity"
|
||||
|
@ -25,12 +27,12 @@ import (
|
|||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/util"
|
||||
api "github.com/documize/community/core/convapi"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/utility"
|
||||
|
||||
"github.com/documize/community/core/event"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"github.com/gorilla/mux"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// AddUser is the endpoint that enables an administrator to add a new user for their orgaisation.
|
||||
|
@ -48,7 +50,7 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
defer utility.Close(r.Body)
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
|
@ -85,12 +87,12 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
userModel.Initials = utility.MakeInitials(userModel.Firstname, userModel.Lastname)
|
||||
userModel.Initials = stringutil.MakeInitials(userModel.Firstname, userModel.Lastname)
|
||||
|
||||
// generate secrets
|
||||
requestedPassword := util.GenerateRandomPassword()
|
||||
userModel.Salt = util.GenerateSalt()
|
||||
userModel.Password = util.GeneratePassword(requestedPassword, userModel.Salt)
|
||||
requestedPassword := secrets.GenerateRandomPassword()
|
||||
userModel.Salt = secrets.GenerateSalt()
|
||||
userModel.Password = secrets.GeneratePassword(requestedPassword, userModel.Salt)
|
||||
|
||||
// only create account if not dupe
|
||||
addUser := true
|
||||
|
@ -419,7 +421,7 @@ func UpdateUser(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
defer utility.Close(r.Body)
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
|
@ -457,7 +459,7 @@ func UpdateUser(w http.ResponseWriter, r *http.Request) {
|
|||
p.Context.Transaction = tx
|
||||
|
||||
user.RefID = userID
|
||||
user.Initials = utility.MakeInitials(user.Firstname, user.Lastname)
|
||||
user.Initials = stringutil.MakeInitials(user.Firstname, user.Lastname)
|
||||
|
||||
err = p.UpdateUser(user)
|
||||
|
||||
|
@ -516,7 +518,7 @@ func ChangeUserPassword(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
defer utility.Close(r.Body)
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
|
@ -548,9 +550,9 @@ func ChangeUserPassword(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
user.Salt = util.GenerateSalt()
|
||||
user.Salt = secrets.GenerateSalt()
|
||||
|
||||
err = p.UpdateUserPassword(userID, user.Salt, util.GeneratePassword(newPassword, user.Salt))
|
||||
err = p.UpdateUserPassword(userID, user.Salt, secrets.GeneratePassword(newPassword, user.Salt))
|
||||
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
|
@ -604,7 +606,7 @@ func ForgotUserPassword(w http.ResponseWriter, r *http.Request) {
|
|||
method := "ForgotUserPassword"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
defer utility.Close(r.Body)
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
|
@ -629,7 +631,7 @@ func ForgotUserPassword(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
token := util.GenerateSalt()
|
||||
token := secrets.GenerateSalt()
|
||||
|
||||
err = p.ForgotUserPassword(user.Email, token)
|
||||
|
||||
|
@ -667,7 +669,7 @@ func ResetUserPassword(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
defer utility.Close(r.Body)
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
|
@ -696,9 +698,9 @@ func ResetUserPassword(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
user.Salt = util.GenerateSalt()
|
||||
user.Salt = secrets.GenerateSalt()
|
||||
|
||||
err = p.UpdateUserPassword(user.RefID, user.Salt, util.GeneratePassword(newPassword, user.Salt))
|
||||
err = p.UpdateUserPassword(user.RefID, user.Salt, secrets.GeneratePassword(newPassword, user.Salt))
|
||||
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue