46 lines
922 B
JavaScript
46 lines
922 B
JavaScript
let {addService} = require("../WebSocket.js");
|
|
|
|
addService(({
|
|
client,
|
|
message,
|
|
end,
|
|
next
|
|
})=>{
|
|
let {type,username,password} = message;
|
|
if(type === 'auth/check')
|
|
{
|
|
let auth = client.store.has('user');
|
|
return end({
|
|
value: auth
|
|
})
|
|
};
|
|
if(type === 'auth/login')
|
|
{
|
|
if(username == 'admin' && password == '123456Kc')
|
|
{
|
|
return end({
|
|
status: 'success'
|
|
})
|
|
}else{
|
|
return end({
|
|
status: 'fail'
|
|
})
|
|
}
|
|
};
|
|
if(type === 'auth/logout')
|
|
{
|
|
let auth = client.store.has('user');
|
|
if(auth)
|
|
{
|
|
client.store.delete('user');
|
|
return end({
|
|
status: 'success'
|
|
})
|
|
}else{
|
|
return end({
|
|
status: 'fail'
|
|
})
|
|
}
|
|
};
|
|
next();
|
|
}); |