Changes
This commit is contained in:
parent
9eac960763
commit
da9196f389
22 changed files with 302 additions and 76 deletions
|
@ -1,6 +1,6 @@
|
|||
package device
|
||||
|
||||
import "nutfactory.org/Matrix/utils"
|
||||
import "git.nutfactory.org/hoernschen/Matrix/utils"
|
||||
|
||||
func New(name string) (err error, device *Device) {
|
||||
err, id := utils.CreateUUID()
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"nutfactory.org/Matrix/utils/database"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils/database"
|
||||
)
|
||||
|
||||
func CreateDevice(device *Device, userId string) (err error) {
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"nutfactory.org/Matrix/config"
|
||||
"nutfactory.org/Matrix/utils"
|
||||
"git.nutfactory.org/hoernschen/Matrix/config"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils"
|
||||
)
|
||||
|
||||
func InitServerSigningKey() (err error) {
|
||||
|
@ -50,6 +50,7 @@ func GetServerSigningKeyHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Use Function
|
||||
func getVerifyKey(server string, id string) (key []byte, err error) {
|
||||
if val, ok := config.VerifyKeys[server][id]; ok {
|
||||
key = val
|
||||
|
|
|
@ -3,7 +3,7 @@ package device
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"nutfactory.org/Matrix/utils/database"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils/database"
|
||||
)
|
||||
|
||||
func CreateKey(key *Key, deviceId string) (err error) {
|
||||
|
|
|
@ -9,12 +9,12 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.nutfactory.org/hoernschen/Matrix/config"
|
||||
"git.nutfactory.org/hoernschen/Matrix/entities/device"
|
||||
"git.nutfactory.org/hoernschen/Matrix/entities/user"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils"
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/gorilla/mux"
|
||||
"nutfactory.org/Matrix/config"
|
||||
"nutfactory.org/Matrix/entities/device"
|
||||
"nutfactory.org/Matrix/entities/user"
|
||||
"nutfactory.org/Matrix/utils"
|
||||
)
|
||||
|
||||
func New(
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"nutfactory.org/Matrix/utils/database"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils/database"
|
||||
)
|
||||
|
||||
func CreateRoomMember(roomId string, userId string) (err error) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package event
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"nutfactory.org/Matrix/utils/database"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils/database"
|
||||
)
|
||||
|
||||
func CreateTransaction(transaction *Transaction) (err error) {
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"nutfactory.org/Matrix/config"
|
||||
"nutfactory.org/Matrix/entities/device"
|
||||
"nutfactory.org/Matrix/utils"
|
||||
"nutfactory.org/Matrix/utils/database"
|
||||
"git.nutfactory.org/hoernschen/Matrix/config"
|
||||
"git.nutfactory.org/hoernschen/Matrix/entities/device"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils/database"
|
||||
)
|
||||
|
||||
type resolveServerNameResponse struct {
|
||||
|
@ -26,7 +26,7 @@ type serverImplementation struct {
|
|||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type resetBody struct {
|
||||
type ResetBody struct {
|
||||
Packetloss float32 `json:"packetloss,omitempty"`
|
||||
UnavailableTill int `json:"unavailableTill,omitempty"`
|
||||
AuthentificationCheck bool `json:"authentificationCheck,omitempty"`
|
||||
|
@ -52,9 +52,10 @@ func GetServerImplementation(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Add a function to set the Config-Params
|
||||
func Reset(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
request := resetBody{}
|
||||
request := ResetBody{}
|
||||
errResponse := utils.CheckRequest(r)
|
||||
if errResponse != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package room
|
||||
|
||||
import "nutfactory.org/Matrix/entities/event"
|
||||
import "git.nutfactory.org/hoernschen/Matrix/entities/event"
|
||||
|
||||
type Room struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
|
@ -15,7 +15,7 @@ type Room struct {
|
|||
Federated bool `json:"federated,omitempty"`
|
||||
}
|
||||
|
||||
type createRoomRequest struct {
|
||||
type CreateRoomRequest struct {
|
||||
Visibility string `json:"visibility,omitempty"`
|
||||
RoomAliasName string `json:"room_alias_name,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
|
@ -23,14 +23,14 @@ type createRoomRequest struct {
|
|||
Invite string `json:"invite,omitempty"`
|
||||
Invite3pid invite3pid `json:"invite_3pid,omitempty"`
|
||||
RoomVersion string `json:"room_version,omitempty"`
|
||||
CreationContent creationContent `json:"creation_content,omitempty"`
|
||||
CreationContent CreationContent `json:"creation_content,omitempty"`
|
||||
InitialState []event.StateEvent `json:"initial_state,omitempty"`
|
||||
Preset string `json:"preset,omitempty"`
|
||||
IsDirect bool `json:"is_direct,omitempty"`
|
||||
PowerLevelContentOverride string `json:"power_level_content_override,omitempty"`
|
||||
}
|
||||
|
||||
type createRoomResponse struct {
|
||||
type CreateRoomResponse struct {
|
||||
RoomId string `json:"room_id,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -40,11 +40,11 @@ type getRoomMemberResponse struct {
|
|||
Chunk []*event.Event `json:"chunk,omitempty"`
|
||||
}
|
||||
|
||||
type joinRoomUserRequest struct {
|
||||
type JoinRoomUserRequest struct {
|
||||
ThirdPartySigned thirdPartySigned `json:"third_party_signed,omitempty"`
|
||||
}
|
||||
|
||||
type joinRoomUserResponse struct {
|
||||
type JoinRoomUserResponse struct {
|
||||
RoomId string `json:"room_id,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ type invite3pid struct {
|
|||
Address string `json:"address,omitempty"`
|
||||
}
|
||||
|
||||
type creationContent struct {
|
||||
type CreationContent struct {
|
||||
Federated bool `json:"m.federate,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"git.nutfactory.org/hoernschen/Matrix/config"
|
||||
"git.nutfactory.org/hoernschen/Matrix/entities/event"
|
||||
"git.nutfactory.org/hoernschen/Matrix/entities/user"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils"
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/gorilla/mux"
|
||||
"nutfactory.org/Matrix/config"
|
||||
"nutfactory.org/Matrix/entities/event"
|
||||
"nutfactory.org/Matrix/entities/user"
|
||||
"nutfactory.org/Matrix/utils"
|
||||
)
|
||||
|
||||
func New(
|
||||
|
@ -47,7 +47,7 @@ func New(
|
|||
|
||||
func CreateRoomHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
request := createRoomRequest{}
|
||||
request := CreateRoomRequest{}
|
||||
errResponse := utils.CheckRequest(r)
|
||||
if errResponse != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
@ -315,7 +315,7 @@ func CreateRoomHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
response := createRoomResponse{RoomId: newRoom.Id}
|
||||
response := CreateRoomResponse{RoomId: newRoom.Id}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
panic(err)
|
||||
|
@ -378,7 +378,7 @@ func GetRoomMemberHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func JoinRoomUserHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
request := joinRoomUserRequest{}
|
||||
request := JoinRoomUserRequest{}
|
||||
errResponse := utils.CheckRequest(r)
|
||||
if errResponse != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
@ -578,7 +578,7 @@ func JoinRoomUserHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
return
|
||||
}
|
||||
response := joinRoomUserResponse{RoomId: roomId}
|
||||
response := JoinRoomUserResponse{RoomId: roomId}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -3,8 +3,8 @@ package room
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"nutfactory.org/Matrix/entities/event"
|
||||
"nutfactory.org/Matrix/utils/database"
|
||||
"git.nutfactory.org/hoernschen/Matrix/entities/event"
|
||||
"git.nutfactory.org/hoernschen/Matrix/utils/database"
|
||||
)
|
||||
|
||||
func CreateRoom(room *Room) (err error) {
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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."}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue