Skip to content

Commit

Permalink
added server id to swagger request (#275)
Browse files Browse the repository at this point in the history
* added server id to swagger request
* added sign in user event
  • Loading branch information
e154 authored Mar 10, 2024
1 parent e6af191 commit 059c968
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
73 changes: 42 additions & 31 deletions api/swagger-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,50 @@
<script src="./swagger-ui-bundle.js" charset="UTF-8"></script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"></script>
<script>
window.onload = function () {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "/api.swagger3.yaml",
dom_id: '#swagger-ui',
docExpansion: 'none',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
requestInterceptor: function(req) {
if (!req.headers.Authorization) {
try {
let {v} = JSON.parse(localStorage.getItem('accessToken'))
v = v.replaceAll("\"", "")
req.headers.Authorization = v
return req
} catch (e) {
window.onload = function () {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "/api.swagger3.yaml",
dom_id: '#swagger-ui',
docExpansion: 'none',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
requestInterceptor: function (req) {
// access token
if (!req.headers.Authorization) {
try {
let {v} = JSON.parse(localStorage.getItem('accessToken'))
v = v.replaceAll("\"", "")
req.headers.Authorization = v
} catch (e) {

}
}
return req
}
});
// End Swagger UI call region
}
}

// server id
try {
let {v} = JSON.parse(localStorage.getItem('serverId'))
v = v.replaceAll("\"", "")
if (v) {
req.headers['X-SERVER-ID'] = v;
}
} catch (e) {

}
return req
}
});
// End Swagger UI call region

window.ui = ui;
};
window.ui = ui;
};
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions common/events/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package events

import m "github.com/e154/smart-home/models"

// EventUpdateUserLocation ...
type EventUpdateUserLocation struct {
UserID int64 `json:"user_id"`
Expand All @@ -32,3 +34,7 @@ type EventDirectMessage struct {
Query string `json:"query"`
Message interface{} `json:"message"`
}

type EventUserSignedIn struct {
User *m.User `json:"user"`
}
5 changes: 5 additions & 0 deletions endpoint/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pkg/errors"

"github.com/e154/smart-home/common/apperr"
"github.com/e154/smart-home/common/events"
m "github.com/e154/smart-home/models"
"github.com/e154/smart-home/plugins/email"
"github.com/e154/smart-home/plugins/notify"
Expand Down Expand Up @@ -76,6 +77,10 @@ func (a *AuthEndpoint) SignIn(ctx context.Context, email, password string, ip st

log.Infof("Successful login, user: %s", user.Email)

a.eventBus.Publish(fmt.Sprintf("system/users/%d", user.Id), events.EventUserSignedIn{
User: user,
})

return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const sendCommand = (text?: string) => {
@resize="handleResize"
:name="'terminal'"
v-show="showTerminal"
:initial-width="600"
:initial-width="800"
:initial-height="400"
>
<template #header>
Expand Down

0 comments on commit 059c968

Please sign in to comment.