Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F12553885
registration.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
registration.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Registration
do
use
Ecto.Schema
import
Ecto.Changeset
alias
Pleroma.Registration
alias
Pleroma.Repo
alias
Pleroma.User
@primary_key
{
:id
,
Pleroma.FlakeId
,
autogenerate
:
true
}
schema
"registrations"
do
belongs_to
(
:user
,
User
,
type
:
Pleroma.FlakeId
)
field
(
:provider
,
:string
)
field
(
:uid
,
:string
)
field
(
:info
,
:map
,
default
:
%{})
timestamps
()
end
def
nickname
(
registration
,
default
\\
nil
),
do
:
Map
.
get
(
registration
.
info
,
"nickname"
,
default
)
def
email
(
registration
,
default
\\
nil
),
do
:
Map
.
get
(
registration
.
info
,
"email"
,
default
)
def
name
(
registration
,
default
\\
nil
),
do
:
Map
.
get
(
registration
.
info
,
"name"
,
default
)
def
description
(
registration
,
default
\\
nil
),
do
:
Map
.
get
(
registration
.
info
,
"description"
,
default
)
def
changeset
(
registration
,
params
\\
%{})
do
registration
|>
cast
(
params
,
[
:user_id
,
:provider
,
:uid
,
:info
])
|>
validate_required
([
:provider
,
:uid
])
|>
foreign_key_constraint
(
:user_id
)
|>
unique_constraint
(
:uid
,
name
:
:registrations_provider_uid_index
)
end
def
bind_to_user
(
registration
,
user
)
do
registration
|>
changeset
(%{
user_id
:
(
user
&&
user
.
id
)
||
nil
})
|>
Repo
.
update
()
end
def
get_by_provider_uid
(
provider
,
uid
)
do
Repo
.
get_by
(
Registration
,
provider
:
to_string
(
provider
),
uid
:
to_string
(
uid
)
)
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sat, Nov 15, 2:35 AM (13 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
570997
Default Alt Text
registration.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment