-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
236 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
defmodule InfinityOne.Plug.SingleLogin do | ||
@moduledoc """ | ||
Plug to allow only one login per user. | ||
Checks to see if another device is logged in for the user. If it finds other | ||
logins, it logs them out. | ||
""" | ||
@behaviour Plug | ||
|
||
import Plug.Conn | ||
|
||
alias InfinityOne.OnePubSub | ||
alias Coherence.CredentialStore.Server | ||
|
||
require Logger | ||
|
||
@session_key Application.get_env(:coherence, :session_key, "session_auth") | ||
|
||
def init(opts) do | ||
%{ | ||
store: Keyword.get(opts, :store, Coherence.CredentialStore.Session), | ||
assigns_key: Keyword.get(opts, :assigns_key, :current_user), | ||
login_key: Keyword.get(opts, :login_cookie, Coherence.Config.login_cookie), | ||
} | ||
end | ||
|
||
def call(conn, opts) do | ||
do_call(conn, opts, Process.whereis(Server)) | ||
end | ||
|
||
defp do_call(conn, _opts, nil) do | ||
conn | ||
end | ||
|
||
defp do_call(conn, opts, pid) do | ||
user = conn.assigns.current_user | ||
logins = | ||
pid | ||
|> :sys.get_state() | ||
|> Map.get(:store) | ||
|> Enum.filter(& elem(&1, 1) == user.id) | ||
|
||
if length(logins) == 1 do | ||
conn | ||
else | ||
key = get_session(conn, @session_key) | ||
if is_nil(key), do: raise("Cannot find the session") | ||
|
||
logins | ||
|> Enum.reject(& elem(&1, 0) == key) | ||
|> Enum.reduce(conn, fn {creds, _}, acc -> | ||
opts.store.delete_credentials(creds) | ||
OnePubSub.broadcast("user:" <> user.id, "logout", %{creds: creds}) | ||
acc | ||
end) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
plugins/one_backup_restore/lib/one_backup_restore/application.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule OneBackupRestore.Application do | ||
@moduledoc """ | ||
Backup and Restore Application module. | ||
Creates the backup path if it does not already exist. | ||
""" | ||
|
||
alias OneBackupRestore.Utils | ||
require Logger | ||
|
||
def start(_, _) do | ||
case File.mkdir_p Utils.backup_path() do | ||
:ok -> | ||
:ok | ||
{:error, error} -> | ||
Logger.error("Could not create backup path #{Utils.backup_path()} - error: #{inspect error}") | ||
:error | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
defmodule OneChat.Mute do | ||
@moduledoc """ | ||
Track mute status for user and channel. | ||
When created, the associated user is muted in the given channel. Delete | ||
the record to unmute them. | ||
""" | ||
use OneModel, schema: OneChat.Schema.Mute | ||
use InfinityOneWeb.Gettext | ||
|
||
alias OneChat.Channel | ||
|
||
@doc """ | ||
Checks if the user is muted in the given channel. | ||
Returns true if the user is muted, false otherwise. | ||
""" | ||
def user_muted?(channel_id, user_id) do | ||
!!get_by(channel_id: channel_id, user_id: user_id) | ||
end | ||
|
||
@doc """ | ||
A prepare changes hook to check that we are not trying to mute in a direct channel. | ||
""" | ||
def prepare_check_channel(%{action: :insert} = changeset) do | ||
if Channel.direct?(changeset.changes.channel_id) do | ||
Ecto.Changeset.add_error(changeset, :channel_id, | ||
~g(can't be muted in a direct message channel)) | ||
else | ||
changeset | ||
end | ||
end | ||
|
||
def prepare_check_channel(changeset) do | ||
changeset | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.