This commit is contained in:
Hoernschen 2020-10-12 16:16:28 +02:00
parent 9eac960763
commit da9196f389
22 changed files with 302 additions and 76 deletions

View file

@ -1,7 +1,7 @@
package user
import (
"nutfactory.org/Matrix/entities/device"
"git.nutfactory.org/hoernschen/Matrix/entities/device"
)
type User struct {
@ -19,8 +19,8 @@ type availableResponse struct {
Available bool `json:"available,omitempty"`
}
type registerRequest struct {
Auth authentificationData `json:"auth,omitempty"`
type RegisterRequest struct {
Auth AuthentificationData `json:"auth,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
DeviceId string `json:"device_id,omitempty"`
@ -28,7 +28,7 @@ type registerRequest struct {
InhibitLogin bool `json:"inhibit_login,omitempty"`
}
type registerResponse struct {
type RegisterResponse struct {
UserId string `json:"user_id,omitempty"`
AccessToken string `json:"access_token,omitempty"`
HomeServer string `json:"home_server,omitempty"`
@ -52,7 +52,7 @@ type loginResponse struct {
}
type deaktivateUserRequest struct {
Auth authentificationData `json:"auth,omitempty"`
Auth AuthentificationData `json:"auth,omitempty"`
IdentityServer string `json:"id_server,omitempty"`
}
@ -63,7 +63,7 @@ type deaktivateUserResponse struct {
type changePasswordRequest struct {
NewPassword string
LogoutDevices bool
Auth authentificationData
Auth AuthentificationData
}
type identifier struct {
@ -75,7 +75,7 @@ type identifier struct {
Phone string `json:"phone,omitempty"`
}
type authentificationData struct {
type AuthentificationData struct {
LoginType string `json:"type,omitempty"`
Session string `json:"session,omitempty"`
}

View file

@ -5,9 +5,9 @@ import (
"fmt"
"net/http"
"nutfactory.org/Matrix/config"
"nutfactory.org/Matrix/entities/device"
"nutfactory.org/Matrix/utils"
"git.nutfactory.org/hoernschen/Matrix/config"
"git.nutfactory.org/hoernschen/Matrix/entities/device"
"git.nutfactory.org/hoernschen/Matrix/utils"
)
func New(username string, name string, password string) (err error, newUser *User) {
@ -69,7 +69,7 @@ func CheckUsernameAvailabilityHandler(w http.ResponseWriter, r *http.Request) {
func RegisterHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
request := registerRequest{}
request := RegisterRequest{}
errResponse := utils.CheckRequest(r)
if errResponse != nil {
w.WriteHeader(http.StatusBadRequest)
@ -120,7 +120,7 @@ func RegisterHandler(w http.ResponseWriter, r *http.Request) {
}
return
}
response := registerResponse{
response := RegisterResponse{
UserId: newUser.Id,
AccessToken: userDevice.AccessToken,
DeviceId: userDevice.Id,
@ -242,15 +242,6 @@ func LogoutHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
//TODO: Check if necessary
func SyncHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusBadRequest)
if err := json.NewEncoder(w).Encode("Not Implemented"); err != nil {
panic(err)
}
}
func checkLoginType(loginType string) (errResponse *utils.ErrorResponse) {
if loginType != "m.login.password" {
errResponse = &utils.ErrorResponse{ErrorCode: "M_UNKNOWN", ErrorMessage: "Bad login type."}

View file

@ -3,8 +3,8 @@ package user
import (
"fmt"
"nutfactory.org/Matrix/entities/device"
"nutfactory.org/Matrix/utils/database"
"git.nutfactory.org/hoernschen/Matrix/entities/device"
"git.nutfactory.org/hoernschen/Matrix/utils/database"
)
func CreateUser(user *User) (err error) {