Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
118c5720
Commit
118c5720
authored
May 10, 2017
by
lain
Browse files
Use changeset for remote user creation.
parent
373753e5
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
118c5720
...
...
@@ -63,13 +63,14 @@ def user_info(%User{} = user) do
@email_regex
~r/^[a-zA-Z0-9.!#$%&'*+\/
=
?^
_
`
{
|
}
~
-
]
+
@
[
a
-
zA
-
Z0
-
9
](
?:
[
a
-
zA
-
Z0
-
9
-
]{
0
,
61
}[
a
-
zA
-
Z0
-
9
])
?(?:
\
.
[
a
-
zA
-
Z0
-
9
](
?:
[
a
-
zA
-
Z0
-
9
-
]{
0
,
61
}[
a
-
zA
-
Z0
-
9
])
?)
*
$
/
def
remote_user_creation
(
params
)
do
changeset
=
%
User
{}
|>
cast
(
params
,
[
:bio
,
:name
,
:ap_id
,
:nickname
,
:info
])
|>
validate_required
([
:bio
,
:name
,
:ap_id
,
:nickname
])
%
User
{}
|>
cast
(
params
,
[
:bio
,
:name
,
:ap_id
,
:nickname
,
:info
,
:avatar
])
|>
validate_required
([
:name
,
:ap_id
,
:nickname
])
|>
unique_constraint
(
:nickname
)
|>
validate_format
(
:nickname
,
@email_regex
)
|>
validate_length
(
:bio
,
max:
1000
)
|>
validate_length
(
:name
,
max:
100
)
|>
put_change
(
:local
,
false
)
end
def
register_changeset
(
struct
,
params
\\
%{})
do
...
...
lib/pleroma/web/ostatus/ostatus.ex
View file @
118c5720
...
...
@@ -211,16 +211,14 @@ def find_or_make_user(uri) do
def
make_user
(
uri
)
do
with
{
:ok
,
info
}
<-
gather_user_info
(
uri
)
do
data
=
%{
local:
false
,
name:
info
[
"name"
],
nickname:
info
[
"nickname"
]
<>
"@"
<>
info
[
"host"
],
ap_id:
info
[
"uri"
],
info:
info
,
avatar:
info
[
"avatar"
]
}
# TODO: Make remote user changeset
# SHould enforce fqn nickname
Repo
.
insert
(
Ecto
.
Changeset
.
change
(%
User
{},
data
))
cs
=
User
.
remote_user_creation
(
data
)
Repo
.
insert
(
cs
)
end
end
...
...
test/user_test.exs
View file @
118c5720
...
...
@@ -146,7 +146,8 @@ test "returns an ap_followers link for a user" do
name:
"Someone"
,
nickname:
"a@b.de"
,
ap_id:
"http..."
,
info:
%{
some:
"info"
}
info:
%{
some:
"info"
},
avatar:
%{
some:
"avatar"
}
}
test
"it confirms validity"
do
...
...
@@ -156,11 +157,13 @@ test "it confirms validity" do
test
"it enforces the fqn format for nicknames"
do
cs
=
User
.
remote_user_creation
(%{
@valid_remote
|
nickname:
"bla"
})
assert
cs
.
changes
.
local
==
false
assert
cs
.
changes
.
avatar
refute
cs
.
valid?
end
test
"it has required fields"
do
[
:bio
,
:name
,
:nickname
,
:ap_id
]
[
:name
,
:nickname
,
:ap_id
]
|>
Enum
.
each
(
fn
(
field
)
->
cs
=
User
.
remote_user_creation
(
Map
.
delete
(
@valid_remote
,
field
))
refute
cs
.
valid?
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment