ImageUpload
parent
9a78c588a1
commit
07ab264175
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"editor.tabSize": 2
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
[server]
|
||||
debug = true
|
||||
host = "127.0.0.1:3000"
|
||||
host = "0.0.0.0:3000"
|
||||
|
||||
[database]
|
||||
host = "127.0.0.1:3306"
|
||||
|
@ -34,3 +34,8 @@ defaultLanguageId = 0
|
|||
emailMaxLen = 255
|
||||
passwordMinLen = 6
|
||||
passwordMaxLen = 250
|
||||
|
||||
[settings.cookies]
|
||||
sessionId = "session_id"
|
||||
username = "username"
|
||||
userHashtag = "user_hashtag"
|
59
example.http
59
example.http
|
@ -1,27 +1,66 @@
|
|||
#### user login
|
||||
|
||||
POST http://localhost:3000/api/v1/user/login
|
||||
Content-Type: application/json
|
||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
|
||||
|
||||
{
|
||||
"email": "107@roese.dev",
|
||||
"password": "bXktcGFzc3dvcmQ="
|
||||
"email": "407@roese.dev",
|
||||
"password": "cGFzc3dvcmQ="
|
||||
}
|
||||
|
||||
### get users
|
||||
### get user
|
||||
POST http://localhost:3000/api/v1/user/
|
||||
Content-Type: application/json
|
||||
Cookie: session_id=C0yPomO6IdEEZCoaUseIRmAAegKXdD9u
|
||||
|
||||
GET http://localhost:3000/api/v1/users
|
||||
Content-Type: application/xml
|
||||
Cookie: session_id=5CLPfNbit0SCNoyRy2AWslJSWTascm3q
|
||||
{
|
||||
"v": ["id", "state", "name"]
|
||||
}
|
||||
|
||||
### get a user by id
|
||||
POST http://localhost:3000/api/v1/users/75538725fe774bb3bdf829a3e2516b2f
|
||||
Content-Type: application/json
|
||||
Cookie: session_id=yXE62jFOR8aJIqGmIVlDvCFGEqtTNQw3
|
||||
|
||||
{
|
||||
"v": ["state", "name"]
|
||||
}
|
||||
|
||||
#### create user
|
||||
|
||||
POST http://localhost:3000/api/v1/users
|
||||
Content-Type: application/json
|
||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
|
||||
|
||||
{
|
||||
"username": "125",
|
||||
"email": "125@roese.dev",
|
||||
"username": "411",
|
||||
"email": "411@roese.dev",
|
||||
"password": "cGFzc3dvcmQ="
|
||||
}
|
||||
|
||||
### delete user
|
||||
DELETE http://localhost:3000/api/v1/user
|
||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
|
||||
Cookie: session_id=RndKK7HlwsOcc1rzQPydAujerIFq6VVd
|
||||
|
||||
### update user
|
||||
|
||||
### active user
|
||||
POST http://localhost:3000/api/v1/user/action/activate/CpQTQiYhJco7qdur
|
||||
Content-Type: application/json
|
||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
|
||||
|
||||
### delete session
|
||||
DELETE http://localhost:3000/api/v1/sessions/n7H4V9UVbv7WaOJqRHaRB3TYRuVgvyGH
|
||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
|
||||
Cookie: session_id=SP2WtO3RcLaLLoUALQINTdf0uGO4yoYh
|
||||
|
||||
### auth session
|
||||
POST http://localhost:3000/api/v1/sessions
|
||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
|
||||
Cookie: session_id=LhL9Hs44ZXhMZexGmIJA7cqs2izSpws7
|
||||
Authorization: Bearer LhL9Hs44ZXhMZexGmIJA7cqs2izSpws7
|
||||
|
||||
### session auth
|
||||
POST http://192.168.178.53:3000/api/v1/sessions
|
||||
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
|
||||
Cookie: session_id=LhL9Hs44ZXhMZexGmIJA7cqs2izSpws7
|
24
go.mod
24
go.mod
|
@ -4,22 +4,12 @@ go 1.16
|
|||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/andybalholm/brotli v1.0.2 // indirect
|
||||
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gofiber/fiber/v2 v2.8.0
|
||||
github.com/gofiber/jwt/v2 v2.2.1 // indirect
|
||||
github.com/gofiber/fiber/v2 v2.12.0
|
||||
github.com/google/uuid v1.2.0
|
||||
github.com/klauspost/compress v1.12.2 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/mileusna/useragent v1.0.2 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/satori/go.uuid v1.2.0 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||
github.com/valyala/fasthttp v1.24.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
github.com/zhengxiaowai/shortuuid v0.0.0-20181208145701-0c38c76c12b3
|
||||
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
github.com/mileusna/useragent v1.0.2
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/streadway/amqp v1.0.0
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
|
||||
gorm.io/driver/mysql v1.1.0
|
||||
gorm.io/gorm v1.21.10
|
||||
)
|
||||
|
|
74
go.sum
74
go.sum
|
@ -1,77 +1,53 @@
|
|||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E=
|
||||
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
|
||||
github.com/form3tech-oss/jwt-go v3.2.3+incompatible h1:7ZaBxOI7TMoYBfyA3cQHErNNyAWIKUMIwqxEtgHOs5c=
|
||||
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/gofiber/fiber/v2 v2.7.1/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0=
|
||||
github.com/gofiber/fiber/v2 v2.8.0 h1:BdWvZmg/WY/Vjtjm38aXOp1Lks1BhuyS2b7lSWSPAzk=
|
||||
github.com/gofiber/fiber/v2 v2.8.0/go.mod h1:Ah3IJikrKNRepl/HuVawppS25X7FWohwfCSRn7kJG28=
|
||||
github.com/gofiber/jwt/v2 v2.2.1 h1:nphRrLNB3t0b7Y2IgHOwv5HXggO1/GBsDSBysCTatHo=
|
||||
github.com/gofiber/jwt/v2 v2.2.1/go.mod h1:PC746ApJVpoQH3I98kmnLGjUM08b8qYVMlaTiNlV0Ao=
|
||||
github.com/gofiber/fiber/v2 v2.12.0 h1:R7FVMs9mtMREjfCzCioh2j8RHwhz0/H+X0rH6BpBkJ4=
|
||||
github.com/gofiber/fiber/v2 v2.12.0/go.mod h1:oZTLWqYnqpMMuF922SjGbsYZsdpE1MCfh416HNdweIM=
|
||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/klauspost/compress v1.11.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/klauspost/compress v1.11.13/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
|
||||
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/klauspost/compress v1.12.2 h1:2KCfW3I9M7nSc5wOqXAlW2v2U6v+w6cbjvbfp+OykW8=
|
||||
github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mileusna/useragent v1.0.2 h1:DgVKtiPnjxlb73z9bCwgdUvU2nQNQ97uhgfO8l9uz/w=
|
||||
github.com/mileusna/useragent v1.0.2/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
|
||||
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.18.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A=
|
||||
github.com/valyala/fasthttp v1.23.0/go.mod h1:0mw2RjXGOzxf4NL2jni3gUQ7LfjjUSiG5sskOUUSEpU=
|
||||
github.com/valyala/fasthttp v1.24.0 h1:AAiG4oLDUArTb7rYf9oO2bkGooOqCaUF6a2u8asBP3I=
|
||||
github.com/valyala/fasthttp v1.24.0/go.mod h1:0mw2RjXGOzxf4NL2jni3gUQ7LfjjUSiG5sskOUUSEpU=
|
||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
||||
github.com/valyala/fasthttp v1.26.0 h1:k5Tooi31zPG/g8yS6o2RffRO2C9B9Kah9SY8j/S7058=
|
||||
github.com/valyala/fasthttp v1.26.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/zhengxiaowai/shortuuid v0.0.0-20181208145701-0c38c76c12b3 h1:03r8Xo0XhTGIMuyJ9x3yrYCumC+T4ycXShfW+Le3Sts=
|
||||
github.com/zhengxiaowai/shortuuid v0.0.0-20181208145701-0c38c76c12b3/go.mod h1:bxh5+Ghwiy6UJxDAPpoOB/L+dq0To9dky7x92nWeSKU=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf h1:B2n+Zi5QeYRDAEodEu72OS36gmTWjgpXr2+cWcBW90o=
|
||||
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226101413-39120d07d75e/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201210223839-7e3030f88018/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 h1:5PbJGn5Sp3GEUjJ61aYbUP6RIo3Z3r2E4Tv9y2z8UHo=
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E=
|
||||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gorm.io/driver/mysql v1.1.0 h1:3PgFPJlFq5Xt/0WRiRjxIVaXjeHY+2TQ5feXgpSpEC4=
|
||||
gorm.io/driver/mysql v1.1.0/go.mod h1:KdrTanmfLPPyAOeYGyG+UpDys7/7eeWT1zCq+oekYnU=
|
||||
gorm.io/gorm v1.21.9/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
|
||||
gorm.io/gorm v1.21.10 h1:kBGiBsaqOQ+8f6S2U6mvGFz6aWWyCeIiuaFcaBozp4M=
|
||||
gorm.io/gorm v1.21.10/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 330 KiB |
Binary file not shown.
After Width: | Height: | Size: 169 KiB |
Binary file not shown.
After Width: | Height: | Size: 169 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 169 KiB |
12
main.go
12
main.go
|
@ -28,11 +28,18 @@ import (
|
|||
"git.umbach.dev/app-idea/rest-api/routers/router"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
/*
|
||||
app.Use(cors.New(cors.Config{
|
||||
AllowOrigins: "http://10.0.2.16, http://127.0.0.1, http://192.168.178.53, http://0.0.0.0",
|
||||
AllowHeaders: "Origin, Content-Type, Accept",
|
||||
AllowCredentials: true,
|
||||
})) */
|
||||
|
||||
config.LoadConfig()
|
||||
|
||||
|
@ -50,3 +57,8 @@ func main() {
|
|||
|
||||
app.Listen(cfg.Host)
|
||||
}
|
||||
|
||||
/*
|
||||
ToDo:
|
||||
- update user password and delete his sessions
|
||||
*/
|
||||
|
|
|
@ -41,6 +41,7 @@ type settings struct {
|
|||
DefaultLanguageId int
|
||||
Expires settingsExpires `toml:"expires"`
|
||||
Lengths settingsLengths `toml:"lengths"`
|
||||
Cookies settingsCookies `toml:"cookies"`
|
||||
}
|
||||
|
||||
type settingsExpires struct {
|
||||
|
@ -62,6 +63,12 @@ type settingsLengths struct {
|
|||
PasswordMaxLen int
|
||||
}
|
||||
|
||||
type settingsCookies struct {
|
||||
SessionId string
|
||||
Username string
|
||||
UserHashtag string
|
||||
}
|
||||
|
||||
func LoadConfig() {
|
||||
toml.DecodeFile("./config.toml", &Cfg)
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
package mailer
|
|
@ -1,70 +0,0 @@
|
|||
package serversettings
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.umbach.dev/app-idea/rest-api/modules/database"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type ServerSettings struct {
|
||||
ExpiredTime int64
|
||||
UsernameMinLen int64
|
||||
UsernameMaxLen int64
|
||||
EmailMinLen int64
|
||||
EmailMaxLen int64
|
||||
PasswordMinLen int64
|
||||
PasswordMaxLen int64
|
||||
}
|
||||
|
||||
var Settings ServerSettings
|
||||
|
||||
func LoadServerSettings() {
|
||||
log.Debug("load server settings from db")
|
||||
|
||||
rows, err := database.DB.Raw("SELECT name, value FROM server_settings").Rows()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("failed to load server settings:", err)
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
var (
|
||||
name string
|
||||
value string
|
||||
)
|
||||
|
||||
for rows.Next() {
|
||||
rows.Scan(&name, &value)
|
||||
|
||||
log.Debugln("server setting:", name, value)
|
||||
|
||||
switch name {
|
||||
case "expired_time":
|
||||
Settings.ExpiredTime = stringToInt(value)
|
||||
case "username_min_len":
|
||||
Settings.UsernameMinLen = stringToInt(value)
|
||||
case "username_max_len":
|
||||
Settings.UsernameMaxLen = stringToInt(value)
|
||||
case "email_min_len":
|
||||
Settings.EmailMinLen = stringToInt(value)
|
||||
case "email_max_len":
|
||||
Settings.EmailMaxLen = stringToInt(value)
|
||||
case "password_min_len":
|
||||
Settings.PasswordMinLen = stringToInt(value)
|
||||
case "password_max_len":
|
||||
Settings.PasswordMaxLen = stringToInt(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func stringToInt(s string) int64 {
|
||||
n, err := strconv.ParseInt(s, 0, 64)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("failed to parse server setting: ", err)
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package structs
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// UserActivation represents a user activation
|
||||
// swagger:model
|
||||
type UserActivation struct {
|
||||
Id string
|
||||
UserId string
|
||||
Expires time.Time
|
||||
}
|
|
@ -1 +1,43 @@
|
|||
package picture
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Test(c *fiber.Ctx) error {
|
||||
|
||||
log.Infoln("header", string(c.Request().Header.ContentType()))
|
||||
|
||||
log.Infoln("formValue", c.FormValue("image"))
|
||||
|
||||
file, err := c.FormFile("image")
|
||||
|
||||
if err != nil {
|
||||
log.Infoln("err1", err)
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
filename := strings.Replace(uuid.New().String(), "-", "", -1)
|
||||
fileExt := strings.Split(file.Filename, ".")[1]
|
||||
image := fmt.Sprintf("%s.%s", filename, fileExt)
|
||||
|
||||
err = c.SaveFile(file, "./img/"+image)
|
||||
|
||||
if err != nil {
|
||||
log.Infoln("err2", err)
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Infoln("err fileUpload:", err)
|
||||
}
|
||||
|
||||
log.Infoln("no error")
|
||||
|
||||
return c.SendStatus(fiber.StatusCreated)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func Login(c *fiber.Ctx) error {
|
|||
input.Password = string(decodedPassword)
|
||||
|
||||
db := database.DB
|
||||
user := structs.User{}
|
||||
user := structs.User{Name: input.Username, Email: input.Email}
|
||||
|
||||
if input.Username != "" {
|
||||
db.Select("id, hashtag, password").Where("name = ?", input.Username).Find(&user)
|
||||
|
@ -71,6 +71,7 @@ func Login(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
if user.Name == "" && user.Email == "" {
|
||||
log.Info("test1", user)
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
|
@ -89,11 +90,13 @@ func Login(c *fiber.Ctx) error {
|
|||
|
||||
expires := getUserSessionExpiresTime()
|
||||
|
||||
c.Cookie(&fiber.Cookie{Name: "session_id", Value: sessionId, Secure: true, HTTPOnly: true, Expires: expires})
|
||||
cfg := cfg.Settings.Cookies
|
||||
|
||||
c.Cookie(&fiber.Cookie{Name: cfg.SessionId, Value: sessionId, Secure: true, HTTPOnly: true, Expires: expires})
|
||||
if user.Name != "" {
|
||||
c.Cookie(&fiber.Cookie{Name: "name", Value: user.Name, Secure: true, Expires: expires})
|
||||
c.Cookie(&fiber.Cookie{Name: cfg.Username, Value: user.Name, Secure: true, Expires: expires})
|
||||
}
|
||||
c.Cookie(&fiber.Cookie{Name: "hashtag", Value: user.Hashtag, Secure: true, Expires: expires})
|
||||
c.Cookie(&fiber.Cookie{Name: cfg.UserHashtag, Value: user.Hashtag, Secure: true, Expires: expires})
|
||||
|
||||
return c.SendStatus(fiber.StatusCreated)
|
||||
}
|
||||
|
|
|
@ -144,10 +144,11 @@ func NewUser(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
expires := getUserSessionExpiresTime()
|
||||
cfg := cfg.Settings.Cookies
|
||||
|
||||
c.Cookie(&fiber.Cookie{Name: "session_id", Value: sessionId, Secure: true, HTTPOnly: true, Expires: expires})
|
||||
c.Cookie(&fiber.Cookie{Name: "username", Value: input.Username, Secure: true, Expires: expires})
|
||||
c.Cookie(&fiber.Cookie{Name: "user_hashtag", Value: input.Hashtag, Secure: true, Expires: expires})
|
||||
c.Cookie(&fiber.Cookie{Name: cfg.SessionId, Value: sessionId, Secure: true, HTTPOnly: true, Expires: expires})
|
||||
c.Cookie(&fiber.Cookie{Name: cfg.Username, Value: input.Username, Secure: true, Expires: expires})
|
||||
c.Cookie(&fiber.Cookie{Name: cfg.UserHashtag, Value: input.Hashtag, Secure: true, Expires: expires})
|
||||
|
||||
log.Debugln("user created", user)
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func isSessionIdValid(sessionId string) bool {
|
|||
var res string
|
||||
db := database.DB
|
||||
|
||||
db.Raw("SELECT session_id FROM sessions WHERE session_id = ?", sessionId).Scan(&res)
|
||||
db.Raw("SELECT "+cfg.Settings.Cookies.SessionId+" FROM sessions WHERE "+cfg.Settings.Cookies.SessionId+" = ?", sessionId).Scan(&res)
|
||||
|
||||
if res == "" {
|
||||
return false
|
||||
|
@ -38,13 +38,13 @@ func DeleteSession(c *fiber.Ctx) error {
|
|||
|
||||
db := database.DB
|
||||
|
||||
userId, err := getUserIdBySessionId(c.Cookies("session_id"))
|
||||
userId, err := getUserIdBySessionId(c.Cookies(cfg.Settings.Cookies.SessionId))
|
||||
|
||||
if err != nil {
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
res := db.Where("user_id = ? AND session_id = ?", userId, c.Cookies("session_id")).Delete(&structs.Session{})
|
||||
res := db.Where("user_id = ? AND session_id = ?", userId, c.Cookies(cfg.Settings.Cookies.SessionId)).Delete(&structs.Session{})
|
||||
|
||||
// session isn't in list
|
||||
if res.RowsAffected == 0 {
|
||||
|
@ -86,7 +86,9 @@ func getUserSessionExpiresTime() time.Time {
|
|||
}
|
||||
|
||||
func SessionIdCheck(c *fiber.Ctx) error {
|
||||
sessionId := c.Cookies("session_id")
|
||||
sessionId := c.Cookies(cfg.Settings.Cookies.SessionId)
|
||||
|
||||
log.Debugln("SessionIdCheck", sessionId)
|
||||
|
||||
if sessionId == "" {
|
||||
return fiber.ErrUnauthorized
|
||||
|
@ -100,3 +102,25 @@ func SessionIdCheck(c *fiber.Ctx) error {
|
|||
|
||||
return fiber.ErrUnauthorized
|
||||
}
|
||||
|
||||
func AuthSession(c *fiber.Ctx) error {
|
||||
sessionId := c.Cookies(cfg.Settings.Cookies.SessionId)
|
||||
|
||||
log.Infoln("cookie", sessionId, c.IP())
|
||||
|
||||
auth := c.Get(fiber.HeaderAuthorization)
|
||||
|
||||
log.Infoln("auth", auth, c.Get("credentials"))
|
||||
|
||||
if sessionId == "" {
|
||||
return fiber.ErrUnauthorized
|
||||
}
|
||||
|
||||
valid := isSessionIdValid(sessionId)
|
||||
|
||||
if valid {
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ func getUserIdBySessionId(sessionId string) (string, error) {
|
|||
db := database.DB
|
||||
session := structs.Session{}
|
||||
|
||||
db.Select("user_id").Where("session_id = ?", sessionId).Find(&session)
|
||||
db.Select("user_id").Where(cfg.Settings.Cookies.SessionId+" = ?", sessionId).Find(&session)
|
||||
|
||||
return session.UserId, nil
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func getUserIdBySessionId(sessionId string) (string, error) {
|
|||
func GetUserById(c *fiber.Ctx) error {
|
||||
// swagger:operation GET /users User user
|
||||
// ---
|
||||
// summary: Informations about the user by id (except password)
|
||||
// summary: Informations about an user by id (except password)
|
||||
// parameters:
|
||||
// - name: v
|
||||
// in: query
|
||||
|
@ -196,7 +196,7 @@ func userInfos(c *fiber.Ctx, userId string) error {
|
|||
if userId == "" {
|
||||
var err error
|
||||
|
||||
userId, err = getUserIdBySessionId(c.Cookies("session_id"))
|
||||
userId, err = getUserIdBySessionId(c.Cookies(cfg.Settings.Cookies.SessionId))
|
||||
|
||||
if err != nil {
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
|
@ -249,7 +249,7 @@ func deleteUser(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
func DeleteUser(c *fiber.Ctx) error {
|
||||
user, err := getUserBySessionId(c.Cookies("session_id"))
|
||||
user, err := getUserBySessionId(c.Cookies(cfg.Settings.Cookies.SessionId))
|
||||
|
||||
if err != nil {
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
|
@ -268,7 +268,6 @@ func DeleteUser(c *fiber.Ctx) error {
|
|||
db.Save(&user)
|
||||
|
||||
rabbitmq.PublishMail(user.Email, 1, user.LanguageId, json.RawMessage(`{"name": "`+user.Name+`",
|
||||
|
||||
"email": "`+user.Email+`",
|
||||
"url": "http://localhost:3000/api/v1/user/action/1/`+userActivationId+`"}`))
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"git.umbach.dev/app-idea/rest-api/routers/api/v1/picture"
|
||||
"git.umbach.dev/app-idea/rest-api/routers/api/v1/user"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
@ -10,7 +11,7 @@ func SetupRoutes(app *fiber.App) {
|
|||
api := app.Group("/api/v1")
|
||||
|
||||
u := api.Group("/user")
|
||||
u.Get("/", user.SessionIdCheck, user.GetUser)
|
||||
u.Post("/", user.SessionIdCheck, user.GetUser)
|
||||
u.Post("/login", user.Login)
|
||||
u.Delete("/", user.DeleteUser)
|
||||
|
||||
|
@ -18,10 +19,14 @@ func SetupRoutes(app *fiber.App) {
|
|||
u.Get("/action/:actionType/:actionId", user.HandleActions)
|
||||
|
||||
s := api.Group("/sessions")
|
||||
s.Post("/", user.AuthSession)
|
||||
s.Delete("/:id", user.SessionIdCheck, user.DeleteSession)
|
||||
|
||||
users := api.Group("/users")
|
||||
users.Post("/", user.NewUser)
|
||||
users.Get("/:id", user.SessionIdCheck, user.GetUserById)
|
||||
users.Post("/:id", user.SessionIdCheck, user.GetUserById)
|
||||
users.Delete("/:id", user.SessionIdCheck, user.DeleteUser)
|
||||
|
||||
pictures := api.Group("/pictures")
|
||||
pictures.Post("/", user.SessionIdCheck, picture.Test)
|
||||
}
|
||||
|
|
30
swagger.yaml
30
swagger.yaml
|
@ -12,14 +12,37 @@ info:
|
|||
title: App-Idea Rest-API Documentation
|
||||
version: 0.0.1
|
||||
paths:
|
||||
/user/activate/:id:
|
||||
/user:
|
||||
get:
|
||||
operationId: user
|
||||
parameters:
|
||||
- description: Example -> { "v"; ["name", "state", "language_id"] }
|
||||
in: query
|
||||
name: v
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: User informations
|
||||
"400":
|
||||
description: Values wrong format
|
||||
summary: Informations about the user (except password)
|
||||
tags:
|
||||
- User
|
||||
/user/activate/{id}:
|
||||
post:
|
||||
operationId: activation
|
||||
parameters:
|
||||
- description: activation id
|
||||
in: query
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: User was activated
|
||||
"401":
|
||||
description: Activation Id not correct or expired
|
||||
description: Activation Id is incorrect or expired
|
||||
summary: Activate user
|
||||
tags:
|
||||
- User
|
||||
|
@ -49,7 +72,7 @@ paths:
|
|||
- User
|
||||
/users:
|
||||
post:
|
||||
operationId: usersNewUser
|
||||
operationId: user
|
||||
parameters:
|
||||
- description: username of the user (length 3-30)
|
||||
in: query
|
||||
|
@ -83,7 +106,6 @@ paths:
|
|||
responses:
|
||||
"201":
|
||||
$ref: '#/definitions/User'
|
||||
description: user created
|
||||
"400":
|
||||
description: format is not correct
|
||||
"422":
|
||||
|
|
Loading…
Reference in New Issue