mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
add settings page
This commit is contained in:
parent
b0f3d40bda
commit
5eb85e28f3
5 changed files with 131 additions and 6 deletions
59
app.rb
59
app.rb
|
@ -52,6 +52,11 @@ get '/signin' do
|
|||
slim :'signin'
|
||||
end
|
||||
|
||||
get '/settings' do
|
||||
require_login
|
||||
slim :'settings'
|
||||
end
|
||||
|
||||
post '/create' do
|
||||
dashboard_if_signed_in
|
||||
@site = Site.new username: params[:username], password: params[:password], email: params[:email], new_tags: params[:tags], is_nsfw: params[:is_nsfw], ip: request.ip
|
||||
|
@ -113,6 +118,60 @@ get '/site_files/new_page' do
|
|||
slim :'site_files/new_page'
|
||||
end
|
||||
|
||||
post '/change_password' do
|
||||
require_login
|
||||
|
||||
if !Site.valid_login?(current_site.username, params[:current_password])
|
||||
current_site.errors.add :password, 'Your provided password does not match the current one.'
|
||||
halt slim(:'settings')
|
||||
end
|
||||
|
||||
current_site.password = params[:new_password]
|
||||
current_site.valid?
|
||||
|
||||
if params[:new_password] != params[:new_password_confirm]
|
||||
current_site.errors.add :password, 'New passwords do not match.'
|
||||
end
|
||||
|
||||
if current_site.errors.empty?
|
||||
current_site.save
|
||||
flash[:success] = 'Successfully changed password.'
|
||||
redirect '/settings'
|
||||
else
|
||||
halt slim(:'settings')
|
||||
end
|
||||
end
|
||||
|
||||
post '/change_name' do
|
||||
require_login
|
||||
current_username = current_site.username
|
||||
|
||||
if current_site.username == params[:name]
|
||||
flash[:error] = 'You already have this name.'
|
||||
redirect '/settings'
|
||||
end
|
||||
|
||||
current_site.username = params[:name]
|
||||
|
||||
if current_site.valid?
|
||||
DB.transaction {
|
||||
current_site.save
|
||||
FileUtils.mv site_base_path(current_username), site_base_path(current_site.username)
|
||||
}
|
||||
|
||||
flash[:success] = "Site/user name has been changed. You will need to use this name to login, <b>don't forget it</b>."
|
||||
redirect '/settings'
|
||||
else
|
||||
halt slim(:'settings')
|
||||
end
|
||||
end
|
||||
|
||||
post '/change_nsfw' do
|
||||
require_login
|
||||
current_site.update is_nsfw: params[:is_nsfw]
|
||||
redirect '/settings'
|
||||
end
|
||||
|
||||
post '/site_files/create_page' do
|
||||
require_login
|
||||
@errors = []
|
||||
|
|
|
@ -77,12 +77,13 @@ class Site < Sequel::Model
|
|||
errors.add :over_capacity, 'We are currently at capacity, and cannot create your home page. We will fix this shortly. Please come back later and try again, our apologies.'
|
||||
end
|
||||
|
||||
if new? && (values[:username].nil? || values[:username].empty? || values[:username].match(BAD_USERNAME_REGEX)) # || USERNAME_SHITLIST.include?(values[:username])
|
||||
if values[:username].nil? || values[:username].empty? || values[:username].match(BAD_USERNAME_REGEX)
|
||||
errors.add :username, 'A valid username is required.'
|
||||
end
|
||||
|
||||
# Check for existing user
|
||||
|
||||
|
||||
user = self.class.select(:id, :username).filter(username: values[:username]).first
|
||||
|
||||
if user
|
||||
|
|
|
@ -26,12 +26,19 @@ html
|
|||
li: a href="/blog" <b>Blog</b>
|
||||
li: a href="/about" <b>About</b>
|
||||
|
||||
|
||||
|
||||
ul.nav.pull-right
|
||||
- if signed_in?
|
||||
li.navbar-text: strong style="color: #7AB800" #{current_site.username}
|
||||
li: a href="/signout" style="color: #B94A48" Signout
|
||||
- else
|
||||
- if !signed_in?
|
||||
li: a href="/signin" <b>Sign in</b>
|
||||
|
||||
- if signed_in?
|
||||
.dropdown.pull-right
|
||||
a.dropdown-toggle.navbar-text data-toggle="dropdown" href="#": strong style="color: #7AB800" #{current_site.username}
|
||||
ul.dropdown-menu role="menu" aria-labelledby="dLabel"
|
||||
li: a href="/dashboard" Dashboard
|
||||
li: a href="/settings" Settings
|
||||
li: a href="/signout" Signout
|
||||
|
||||
- flash.keys.each do |key|
|
||||
div class="alert alert-#{key}"
|
||||
|
|
|
@ -26,7 +26,7 @@ javascript:
|
|||
h5 Username
|
||||
.span6
|
||||
p <input name="username" type="text" placeholder="yourusername" value="#{@site.username}" autocapitalize="off" autocorrect="off">.neocities.org
|
||||
|
||||
|
||||
.row
|
||||
.span6
|
||||
p Next, enter a password. This will be used to allow you to login. Minimum 5 characters. If you don't make it a good password, Dade Murphy from the movie Hackers will come in and steal your "garbage files".
|
||||
|
|
58
views/settings.slim
Normal file
58
views/settings.slim
Normal file
|
@ -0,0 +1,58 @@
|
|||
.row
|
||||
.span12.text-center
|
||||
h1 Site Settings
|
||||
|
||||
.row
|
||||
.span12.text-center
|
||||
- if !current_site.errors.empty?
|
||||
.row
|
||||
.span8.offset2
|
||||
.alert.alert-block.alert-error
|
||||
- current_site.errors.each do |error|
|
||||
p = error.last.first
|
||||
|
||||
.row
|
||||
.span4
|
||||
h2 Change Password
|
||||
form method="POST" action="/change_password"
|
||||
input name="csrf_token" type="hidden" value="#{csrf_token}"
|
||||
|
||||
div
|
||||
p Current Password:
|
||||
input name="current_password" type="password"
|
||||
|
||||
div
|
||||
p New Password:
|
||||
input name="new_password" type="password"
|
||||
|
||||
div
|
||||
p Confirm New Password:
|
||||
input name="new_password_confirm" type="password"
|
||||
|
||||
input.btn.btn-success type="submit" value="Change Password"
|
||||
.span4
|
||||
h2 Change Site (User) Name
|
||||
|
||||
form method="POST" action="/change_name"
|
||||
input name="csrf_token" type="hidden" value="#{csrf_token}"
|
||||
|
||||
p It cannot contain spaces, and can only use the following characters: a-z A-Z 0-9 _ -
|
||||
|
||||
div
|
||||
p Current name: <span style="color: green"><strong>#{current_site.username}</strong></span>
|
||||
div
|
||||
p New name:
|
||||
input name="name" type="text" placeholder="newname"
|
||||
div
|
||||
input.btn.btn-success type="submit" value="Change Name"
|
||||
|
||||
.span4
|
||||
h2 Mark Adult Content
|
||||
p If your site contains objectionable (adult) content, check this box. Your site will not be removed, but it will be listed on a special browse page. We don't have an official policy on what defines "adult" content yet, we are still working on this. In the interim, best guesses. Thanks for your patience as we try to find a way to balance out the needs of everyone.
|
||||
|
||||
form method="POST" action="/change_nsfw"
|
||||
input name="csrf_token" type="hidden" value="#{csrf_token}"
|
||||
input name="is_nsfw" type="hidden" value="false"
|
||||
p: strong My page contains objectionable (adult) content: <input name="is_nsfw" type="checkbox" value="true" style="margin-top: 0px" #{"checked" if current_site.is_nsfw}>
|
||||
|
||||
input.btn.btn-success type="submit" value="Update"
|
Loading…
Add table
Reference in a new issue