ishapi 0.1.8.181 → 0.1.8.182

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ef65cf53c1c9ed63d5118cba183a30c1958a00c5a7e45d23fc15e32605782f4
4
- data.tar.gz: 3be58b188615387a0ed57107bb1ba3378327838bb4ec48f012ead15ca0cc8dab
3
+ metadata.gz: d463a329bf3e455dd44020f402062b623d7dbf9a832d30e84c73792d2afee35d
4
+ data.tar.gz: 6090044a2ebccee0ae47e4e908a652998163385e18cbfd26451e8ec0f0aa0889
5
5
  SHA512:
6
- metadata.gz: 292432e6e0f2d4410b0440d849a7cea5409bc52cc8cb03e2f30befdb80de9296a8b560e70ae22368aa55c50a8e3007d42698920d607fd88e451977e98a41b26a
7
- data.tar.gz: 015ca8524e54cee60bae0bfac3afe86c092856cd3028091963a2b4e3eab9ddb6e128025512762f35419aaed2e47ce2fdbf059c9c0e597e1278610492fcce3bb7
6
+ metadata.gz: 6e0fe6f94cb204b9464d7c48d19a243cd13329ee7c4c076d0deae8db0622d3f7d86d1be643c0cec5d710da3fa4015843a583c246e1c1a8f61149b758f5e1ce55
7
+ data.tar.gz: d70c30f52193fc1db730dae238217c1b651db64b17aea8257968f1ece64e3534f8710528b6c0940db7ee044c0a053bc29c491ed6ee7410a4c13fa61e8ae81af0
@@ -32,6 +32,24 @@ class Ishapi::ApplicationController < ActionController::Base
32
32
  }
33
33
  end
34
34
 
35
+ ## @TODO: implement completely! _vp_ 2022-08-24
36
+ def vote
37
+ votee = params[:votee_class_name].constantize.find(params[:votee_id])
38
+ out = votee.vote(voter_id: params[:voter_id], value: params[:value].to_sym)
39
+
40
+ if out
41
+ render json: {
42
+ status: 'ok',
43
+ }
44
+ else
45
+ render json: {
46
+ status: 'not_ok',
47
+ message: votee.errors.full_messages.join(', '),
48
+ }
49
+ end
50
+
51
+ end
52
+
35
53
  private
36
54
 
37
55
  ## This returns an empty user if not logged in!
@@ -24,7 +24,7 @@ module Ishapi
24
24
  @gallery = ::Gallery.unscoped.find_by :slug => params[:slug]
25
25
  authorize! :show, @gallery
26
26
  if @gallery.premium?
27
- if current_user&.profile&.has_premium_purchase( @gallery )
27
+ if @current_user&.profile&.has_premium_purchase( @gallery )
28
28
  render 'show_premium_unlocked'
29
29
  else
30
30
  render 'show_premium_locked'
@@ -5,13 +5,14 @@ class Ishapi::MapsController < Ishapi::ApplicationController
5
5
  before_action :check_profile, only: [ :show ]
6
6
 
7
7
  def show
8
- @location = ::Gameui::Map.find_by slug: params[:slug]
8
+ @location = ::Gameui::Map.where( slug: params[:slug] ).first
9
+ @location ||= ::Gameui::Map.find params[:slug]
9
10
  @map = @location.map || @location
10
11
 
11
12
  authorize! :show, @map
12
13
  @newsitems = @location.newsitems
13
14
 
14
- @markers = @map.markers.permitted_to(current_user.profile)
15
+ @markers = @map.markers.permitted_to(@current_user.profile)
15
16
 
16
17
  @tags = @map.tags
17
18
 
@@ -0,0 +1,37 @@
1
+
2
+ class Ishapi::Users::RegistrationsController < Devise::RegistrationsController
3
+ skip_before_action :verify_authenticity_token
4
+
5
+ def create
6
+ build_resource(sign_up_params)
7
+ resource.save
8
+ resource.profile = Ish::UserProfile.create({ user: resource, email: resource.email })
9
+ yield resource if block_given?
10
+ if resource.persisted?
11
+ render json: {
12
+ status: :ok,
13
+ message: "You have successfully registered! Please verify your email by clicking on a link we just sent you, before logging in.",
14
+ }, status: 200
15
+
16
+ # if resource.active_for_authentication?
17
+ # set_flash_message! :notice, :signed_up
18
+ # sign_up(resource_name, resource)
19
+ # respond_with resource, location: after_sign_up_path_for(resource)
20
+ # else
21
+ # set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
22
+ # expire_data_after_sign_in!
23
+ # respond_with resource, location: after_inactive_sign_up_path_for(resource)
24
+ # end
25
+ else
26
+ render json: {
27
+ status: :not_ok,
28
+ message: "Cannot register: #{resource.errors.full_messages.join(', ')}",
29
+ }, status: 400
30
+
31
+ # clean_up_passwords resource
32
+ # set_minimum_password_length
33
+ # respond_with resource
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,35 @@
1
+
2
+ class Ishapi::Users::SessionsController < Devise::SessionsController
3
+ skip_before_action :verify_authenticity_token
4
+
5
+ def create
6
+ self.resource = warden.authenticate!(auth_options)
7
+ set_flash_message!(:notice, :signed_in)
8
+ sign_in(resource_name, resource)
9
+ yield resource if block_given?
10
+ # respond_with resource, location: after_sign_in_path_for(resource)
11
+
12
+ ## Send the jwt to client
13
+ @jwt_token = encode(user_id: @current_user.id.to_s)
14
+ @profile = @current_user.profile
15
+ render 'ishapi/users/login', format: :json, layout: false
16
+ end
17
+
18
+ private
19
+
20
+ ## copy-pasted from application_controller
21
+ ## jwt
22
+ def decode(token)
23
+ decoded = JWT.decode(token, Rails.application.secrets.secret_key_base.to_s)[0]
24
+ HashWithIndifferentAccess.new decoded
25
+ end
26
+
27
+ ## copy-pasted from application_controller
28
+ ## jwt
29
+ def encode(payload, exp = 48.hours.from_now) # @TODO: definitely change, right now I expire once in 2 days.
30
+ payload[:exp] = exp.to_i
31
+ JWT.encode(payload, Rails.application.secrets.secret_key_base.to_s)
32
+ end
33
+
34
+
35
+ end
@@ -1,14 +1,15 @@
1
- require_dependency "ishapi/application_controller"
1
+ # require_dependency "ishapi/application_controller"
2
2
 
3
3
  module Ishapi
4
- class UsersController < ApplicationController
4
+ class UsersController < Ishapi::ApplicationController
5
5
 
6
6
  skip_authorization_check only: %i| create fb_sign_in login |
7
7
 
8
+
8
9
  before_action :check_profile_hard, only: %i| account |
9
10
 
10
11
  def account
11
- @profile = current_user&.profile
12
+ @profile = @current_user&.profile
12
13
  authorize! :show, @profile
13
14
  render 'ishapi/users/account'
14
15
  rescue CanCan::AccessDenied
@@ -18,16 +19,19 @@ module Ishapi
18
19
  end
19
20
 
20
21
  def create
21
- @profile = Profile.new( email: params[:email] )
22
- @user = User.new( email: params[:email], password: params[:password], profile: @profile )
22
+ authorize! :open_permission, Ishapi
23
+ new_user_params = params[:user].permit!
24
+
25
+ @profile = Profile.new( email: new_user_params[:email] )
26
+ @user = User.new( email: new_user_params[:email], password: new_user_params[:password], profile: @profile )
23
27
 
24
28
  if @profile.save && @user.save
25
29
  @jwt_token = encode(user_id: @user.id.to_s)
26
30
  render 'login'
27
31
  else
28
32
  render json: {
29
- messages: [],
30
- }, status: 401
33
+ messages: @user.errors.messages.merge( @profile.errors.messages ),
34
+ }, status: 400
31
35
  end
32
36
  end
33
37
 
@@ -37,21 +41,5 @@ module Ishapi
37
41
  render :action => 'show'
38
42
  end
39
43
 
40
- def login
41
- @current_user = User.where( email: params[:email] ).first
42
-
43
- if !@current_user
44
- render json: { status: :not_ok }, status: 401
45
- return
46
- end
47
- if @current_user.valid_password?(params[:password])
48
- # from: application_controller#long_term_token
49
-
50
- # send the jwt to client
51
- @jwt_token = encode(user_id: @current_user.id.to_s)
52
- @profile = @current_user.profile
53
- end
54
- end
55
-
56
44
  end
57
45
  end
@@ -1,6 +1,6 @@
1
- module Ishapi
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
5
- end
1
+
2
+ class Ishapi::ApplicationMailer < ActionMailer::Base
3
+ default from: '314658@gmail.com'
4
+ layout 'mailer'
6
5
  end
6
+
@@ -0,0 +1,14 @@
1
+
2
+ class Ishapi::ConfirmationsMailer < Devise::Mailer
3
+ # default from: '314658@gmail.com'
4
+ helper :application # gives access to all helpers defined within `application_helper`.
5
+ include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
6
+
7
+ default template_path: 'ishapi/mailer' # to make sure that your mailer uses the devise views
8
+
9
+ def confirmation_instructions(record, token, opts={})
10
+ # headers["Custom-header"] = "Bar"
11
+ super
12
+ end
13
+
14
+ end
@@ -0,0 +1,6 @@
1
+
2
+ <p>Welcome <%= @email %>!</p>
3
+
4
+ <p>You can confirm your account email through the link below:</p>
5
+
6
+ <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @email %>!</p>
2
+
3
+ <% if @resource.try(:unconfirmed_email?) %>
4
+ <p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
5
+ <% else %>
6
+ <p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
7
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>We're contacting you to notify you that your password has been changed.</p>
@@ -0,0 +1,8 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Someone has requested a link to change your password. You can do this through the link below.</p>
4
+
5
+ <p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
6
+
7
+ <p>If you didn't request this, please ignore this email.</p>
8
+ <p>Your password won't change until you access the link above and create a new one.</p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
4
+
5
+ <p>Click the link below to unlock your account:</p>
6
+
7
+ <p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
@@ -12,6 +12,12 @@ json.newsitems do
12
12
 
13
13
  json.description item.description
14
14
 
15
+ json.votes_score item.votes_score
16
+ if @current_user&.profile
17
+ json.current_user_vote_value item.vote_value(@current_user.profile.id)
18
+ end
19
+
20
+
15
21
  if item.gallery
16
22
  json.id item.gallery_id.to_s
17
23
  json.item_type item.gallery.class.name
@@ -62,9 +68,9 @@ json.newsitems do
62
68
 
63
69
  if item.video
64
70
  json.id item.video_id.to_s
65
- # @TODO: why this relation is so weird here?!
71
+ ## @TODO: why is this relation here? It's non-performant.
66
72
  video = Video.unscoped.find( item.video_id )
67
- json.item_type video.class.name
73
+ json.item_type "Video"
68
74
  json.partial! 'ishapi/videos/show', :video => video
69
75
  end
70
76
 
@@ -2,4 +2,4 @@
2
2
  json.email @profile.email
3
3
  json.n_unlocks @profile.n_unlocks
4
4
  json.jwt_token @jwt_token
5
- json.partial! 'account'
5
+ json.partial! 'ishapi/users/account'
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
+
1
2
  Ishapi::Engine.routes.draw do
3
+
2
4
  root :to => 'application#home'
3
5
  post 'home', :to => 'application#home'
4
6
 
@@ -65,8 +67,12 @@ Ishapi::Engine.routes.draw do
65
67
  post 'users/profile/update', to: 'user_profiles#update'
66
68
  get 'users/profile', to: 'users#show' # @TODO: only for testing! accessToken must be hidden
67
69
  match 'users/long_term_token', to: 'application#long_term_token', via: [ :get, :post ]
68
- post 'users/login', to: 'users#login'
69
- post 'users', to: 'users#create'
70
+ devise_scope :user do
71
+ post 'users/register', to: 'users/registrations#create'
72
+ post 'users/login', to: 'users/sessions#create'
73
+ end
74
+
75
+ post 'v1/vote/:votee_class_name/:votee_id/:voter_id/:value', to: 'application#vote'
70
76
 
71
77
  get 'venues', :to => 'venues#index'
72
78
  get 'venues/view/:venuename', :to => 'venues#show'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ishapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.181
4
+ version: 0.1.8.182
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-14 00:00:00.000000000 Z
11
+ date: 2022-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: devise
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
237
251
  description: " Description of Ishapi."
238
252
  email:
239
253
  - piousbox@gmail.com
@@ -273,12 +287,15 @@ files:
273
287
  - app/controllers/ishapi/stock_watches_controller.rb
274
288
  - app/controllers/ishapi/tags_controller.rb
275
289
  - app/controllers/ishapi/user_profiles_controller.rb
290
+ - app/controllers/ishapi/users/registrations_controller.rb
291
+ - app/controllers/ishapi/users/sessions_controller.rb
276
292
  - app/controllers/ishapi/users_controller.rb
277
293
  - app/controllers/ishapi/venues_controller.rb
278
294
  - app/controllers/ishapi/videos_controller.rb
279
295
  - app/helpers/ishapi/application_helper.rb
280
296
  - app/jobs/ishapi/application_job.rb
281
297
  - app/mailers/ishapi/application_mailer.rb
298
+ - app/mailers/ishapi/confirmations_mailer.rb
282
299
  - app/models/ishapi/ability.rb
283
300
  - app/views/ishapi/addresses/_show.jbuilder
284
301
  - app/views/ishapi/application/_meta.jbuilder
@@ -300,6 +317,11 @@ files:
300
317
  - app/views/ishapi/galleries/show.jbuilder
301
318
  - app/views/ishapi/galleries/show_premium_locked.jbuilder
302
319
  - app/views/ishapi/galleries/show_premium_unlocked.jbuilder
320
+ - app/views/ishapi/mailer/confirmation_instructions.html.erb
321
+ - app/views/ishapi/mailer/email_changed.html.erb
322
+ - app/views/ishapi/mailer/password_change.html.erb
323
+ - app/views/ishapi/mailer/reset_password_instructions.html.erb
324
+ - app/views/ishapi/mailer/unlock_instructions.html.erb
303
325
  - app/views/ishapi/maps/_show.jbuilder
304
326
  - app/views/ishapi/maps/index.jbuilder
305
327
  - app/views/ishapi/maps/show.jbuilder