Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
useradm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Root
useradm
Commits
e49eca75
Project 'c3root/useradm' was moved to 'root/useradm'. Please update any links and bookmarks that may still have the old path.
Commit
e49eca75
authored
4 months ago
by
Theo
Browse files
Options
Downloads
Patches
Plain Diff
Sorcery to unify genLogin* functions
parent
834f68fe
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/user/create.go
+26
-81
26 additions, 81 deletions
cmd/user/create.go
with
26 additions
and
81 deletions
cmd/user/create.go
+
26
−
81
View file @
e49eca75
...
...
@@ -231,42 +231,47 @@ func genGecos(u model.User) model.User {
return
u
}
// basically takes the initials and the grr year.
// if variance increases we take next letter of
// 1st name, then next letter of 2nd name, etc...
func
genLoginIni
(
name
string
,
grr
string
,
variance
int
)
string
{
// honestly... i had 3 functions that had a similar algorithm
// and one that only redirected the flow. so i took it as a
// challenge to merge them into one :D this it the result.
// don't even bother trying to understand it, just go back
// a few commits and read there
func
genLogin
(
name
,
grr
,
ltype
string
,
variance
int
)
string
{
fix
:=
1
login
:=
""
var
solo
string
parts
:=
formatName
(
name
)
if
len
(
parts
)
==
0
{
if
len
(
parts
)
<=
1
{
if
ltype
!=
"ini"
||
len
(
parts
)
==
0
{
return
"_"
}
}
if
ltype
==
"first"
{
login
,
parts
,
fix
=
parts
[
0
],
parts
[
1
:
],
0
variance
++
}
if
ltype
==
"last"
{
solo
,
parts
=
parts
[
len
(
parts
)
-
1
],
parts
[
:
len
(
parts
)
-
1
]
}
x
:=
variance
/
len
(
parts
)
y
:=
variance
%
len
(
parts
)
for
i
:=
range
parts
{
if
y
!=
0
{
login
+=
parts
[
i
][
:
x
+
2
]
login
+=
parts
[
i
][
:
x
+
1
+
fix
]
y
--
}
else
{
login
+=
parts
[
i
][
:
x
+
1
]
login
+=
parts
[
i
][
:
x
+
fix
]
}
}
return
login
+
grr
[
2
:
4
]
}
if
ltype
==
"ini"
{
login
+
=
grr
[
2
:
4
]
}
if
ltype
==
"last"
{
login
+=
solo
}
// parent function for generating a login automatically
func
genLogin
(
name
string
,
grr
string
,
ltype
string
,
variance
int
)
string
{
var
login
string
switch
ltype
{
case
""
,
"ini"
:
login
=
genLoginIni
(
name
,
grr
,
variance
)
case
"first"
:
login
=
genLoginFirst
(
name
,
variance
)
case
"last"
:
login
=
genLoginLast
(
name
,
variance
)
}
return
login
}
...
...
@@ -286,66 +291,6 @@ func formatName(name string) []string {
return
parts
}
// basically takes 1st name and the initial of the 2nd.
// if variance increases we take more initials, and if
// it keeps going we put more letters in each name
func
genLoginFirst
(
name
string
,
variance
int
)
string
{
parts
:=
formatName
(
name
)
if
len
(
parts
)
==
0
{
return
"_"
}
// Separate first name
first
,
parts
:=
parts
[
0
],
parts
[
1
:
]
login
:=
first
variance
++
x
:=
variance
/
len
(
parts
)
y
:=
variance
%
len
(
parts
)
for
i
:=
range
parts
{
if
y
!=
0
{
login
+=
parts
[
i
][
:
x
+
1
]
y
--
}
else
{
login
+=
parts
[
i
][
:
x
]
}
}
return
login
}
// basically takes initials up to last name and then appends it.
// if variance increases we put more letters in each name
func
genLoginLast
(
name
string
,
variance
int
)
string
{
login
:=
""
parts
:=
formatName
(
name
)
if
len
(
parts
)
<=
1
{
return
"_"
}
// Separate last name
last
,
parts
:=
parts
[
len
(
parts
)
-
1
],
parts
[
:
len
(
parts
)
-
1
]
x
:=
variance
/
len
(
parts
)
y
:=
variance
%
len
(
parts
)
for
i
:=
range
parts
{
if
y
!=
0
{
login
+=
parts
[
i
][
:
x
+
2
]
y
--
}
else
{
login
+=
parts
[
i
][
:
x
+
1
]
}
}
login
+=
last
return
login
}
func
genUniqueUID
(
name
,
grr
,
ltype
string
,
users
[]
model
.
User
)
(
string
,
error
)
{
var
uid
string
used
,
variance
:=
true
,
0
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment