non-customized devise reset password button is doing absolutely nothing - ruby-on-rails

I have devise login and logout working, been using it for a while now.
I have not copied devise's password controller or password views to my application, just using the out of the box form for password/new. After entering the email of a valid user, when I click the "send me password reset instructions" button, nothing happens. I checked my logs and there is no activity post-click. I've read through devise documentation but it doesn't seem like there is any special setup steps to get the reset password functionality working. What could be wrong?
For more context, I have followed devise's instructions for requiring admin to activate account before sign in. I have pulled the registrations and sessions controllers into my app for minimal customization, though that doesn't seem like it should matter. I'm using rails 4.2.0.rc2 and devise 3.4.1
Here's the rendered html for the form:
<h2>Forgot your password?</h2>
<form class="new_user" id="new_user" action="/users/password" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="AE+YY8afzRavKa1ziDFZ5Z6FqFYQF1vI+zvc701JGqfg5k+ztvMIKHDX4Wdfr+KOp9yEcRBTsk4jfonpzUeP5w==" />
<div class="field">
<label for="user_email">Email</label><br />
<input autofocus="autofocus" type="email" value="" name="user[email]" id="user_email" />
</div>
<div class="actions">
<input type="submit" name="commit" value="Send me reset password instructions" />
</div>
</form>

your javascript is preventing the form from being submitted unless a terms-of-service field is checked.
from your application.js file:
if $('#user_terms').is(':checked')
else
e.preventDefault()
$('#terms-of-service-error').modal()
return

Related

Unable to store cookies in Rails

LoginController:
class LoginController < ApplicationController
def new
cookies[:id]=rand(1000)
render "index"
end
end
index.html.erb:
<body>
<center>
<h1> Login </h1>
<form action='login/auth' method='POST'>
Name: <input type="text" name="name" widht=20><br>
Password: <input type="password" name="pass" widht=20><br>
<input type="submit" value="submit">
</form>
</center>
<br><br>
</body>
My requirement is, if login page is called, the response page should send with a cookie. So, I create a cookie with a random number in
new action. But the page "index.html" didn't have cookie in browser. But it is properly worked if "new" action call its default view file
"new.html.erb". Why the cookie only works in default view and not in some other view file. How to solve this problem ?
FYI, you have two typos in the form. "width" is typed as "widht."
<form action='login/auth' method='POST'>
Name: <input type="text" name="name" widht=20><br>
Password: <input type="password" name="pass" widht=20><br>
<input type="submit" value="submit">
</form>
This won't solve the problem, but it will remove one more error once the problem is solved.
Related to the original problem, I wonder if it could be that when you want to pass a variable to a non-default view, you may need an instance variable (but since cookies aren't expressed as instance variables, I'm not sure where to go with that)

Submitting form through iframe: Rails 4 InvalidAuthenticityToken in Chrome, Safari

I have a form on a page which other people can embed through an iframe on their sites. When submitting that form I get an ActionController::InvalidAuthenticityToken error, in Safari and also Chrome (with third-party cookies turned off) but not in Firefox.
My understanding was that I don't have to rely on third-party cookies being activated if I've got this in my header:
<head>
<%= csrf_meta_tags %>
</head>
But apparently that's not true...?
And I'm even seeing the token in my server log:
Parameters: {"utf8"=>"✓", "authenticity_token"=> "2ig3BPn9...
Can't verify CSRF token authenticity
So what's going on here?
From the ActionController::RequestForgeryProtection docs:
Controller actions are protected from Cross-Site Request Forgery (CSRF) attacks by including a token in the rendered HTML for your application. This token is stored as a random string in the session, to which an attacker does not have access. When a request reaches your application, Rails verifies the received token with the token in the session.
So even if you embed the token with csrf_meta_tags you still need it also in the session (i.e. in the cookie). That's why with disabled third-party cookies it doesn't work in the iframe.
into form insert:
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>"/>
Ex:
<form name="as" target="open_here" method="get" action="material">
<input type="hidden" name="materialid" value="56"/>
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>"/>
<input type="submit" value="Submit open_here" />
</form>
or
<form name="unit" target="open_here" method="get" action="/redmine/issues_materials/material" >
<input type="hidden" id="material_id" name="materialid" value="" /><!-- valo value e inputado pelo script 2 document.getElementById('material_id').value = materialid; -->
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>"/> <!-- para funcionar tem que enviar essa chave junto-->
<input id="idunit" type="submit" value="open here submit" style="display: none;"/>
</form>
<iframe id="open_here" name="open_here" frameborder="0" scrolling="no" width="60" height="80"></iframe>

How do I edit a user's info in rails app?

I have built a small and simple rails app that I deployed on heroku where you have to sign up as a user by creating a profile, after which you can enter an address or zipcode to find the nearest gyms in your vicinity, which triggers the google places/geocoder api and brings you some results.
My issue is that in trying to CRUD my app, I can't get the U, basically the update to work. I'll paste my code below and as you'll see I put a binding.pry and tested it directly in the rails console to see if my code is right and it works, I'm able to edit a user's info which is then updated when I go into psql and look in my db. But trying to use the browser to make the update does not work.
This is in my users_controller.rb file:
def update
#user = User.find(params[:id])
# binding.pry
#user.update(name: params[:name], password: params[:password], email: params[:email], zipcode: params[:zipcode])
redirect_to '/users'
end
This is the template code:
<h4 id="edit"> Edit your profile below: </h4>
<form action="/users/<%= #user.id%>" method="POST">
<div id="label">
<label>
<input id="one" name="name" placeholder="Edit name"/>
</label>
<label>
<input id="two" name="email" placeholder="Edit email"/>
</label>
<br>
<br>
<label>
<input id="three" name="password" placeholder="Edit password"/>
</label>
<label>
<input id="four" name="zipcode" placeholder="Edit zipcode"/>
</label>
</div>
<input name="_method" value="PUT" type="hidden" />
<input name="authenticity_token" value="<%= form_authenticity_token()%>" type="hidden">
<div id="update">
<br>
<button id="update">Update your profile</button>
</div>
</form>
The routes work and I'm taken to a confirmation page that I set up, but when I try to login with my updated info, the old info is still persistent. No errors are shown either that stop me from doing anything in the app. Any help is greatly appreciated, thank you!
I see these errors in my terminal:
, #messages={:email=>["Not a valid email format"]}>
, #messages={:email=>["Not a valid email format"]}>
Solved I used the advice of RichadAE and looked into the logs of my terminal to see the error messages and I saw that one of the errors was that when I was updating my user info, I was just updating the name or the zip for testing purposes which is fine, but because I am using the gem 'validates_email_format_of' the email field cannot be left blank even when updating otherwise it breaks my code, I tried to edit the name and filled in the email input field to meet the requirement and it worked!!! Thank you for your help!!

HTML 5- How to prevent email validation from input box from type='email'

on submit button when invalid email don't get email address on alert in controller.js file
also used the #scope
<form ng-show="!subscribeSuccess" ng-submit="subscribeNewsLetter(subscribEmailAddress)" novalidate>
<input type="email" name="subscribEmailAddress" placeholder="SHOP.SUBSCRIBE_PLACEHOLDER" ng- model="subscribEmailAddress" translate>
<button type="submit" name="commit" class="action-button" translate>SHOP.SUBSCRIBE</button>
</form>
use novalidate attribute:
<input type="email" novalidate/>
The novalidate attribute simply tells the browser to disable the built-in HTML5 validation, or ignore any HTML5 validation attributes you may have used.
disable validation and your email address go to scope
like <input type="text" />

Basic form action not working on heroku (but works locally)

EDIT: I feel so stupid, I wasn't merging my branches properly with git. Like I said, I am quite new to programming and am prone to these types of errors. I appreciate the help, though.
I am on ch. 7 of the Rails by Example book, where I created a basic "Sign up" form. When I submit the form on my localhost, it works properly by directing me to either
LOCALHOST/new (back to sign up page, registration info error) or LOCALHOST/show (user profile, success).
When I push this same app to heroku and hit the submit button, it always leads me to this url:
appname.heroku.com/form_action.asp?fname=&email=&password=&password= which tells me
"The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved."
Instead of appname.heroku.com/new or /show.
I am so confused, I am a beginner programmer and it boggles my mind why things work so perfectly on the localhost but not on the production server. Please help!
My code is on github:
https://github.com/Chamza/Sample-App2
Are you running the 'cedar' stack on Heroku? I believe the url should be appname.herokuapp.com -- not appname.heroku.com. Since your code in github is based using rails 3.2.1, you should be using the cedar stack.
Here's some information on the cedar stack from heroku: https://devcenter.heroku.com/articles/cedar
Also, can you run heroku logs --tail --app my-app-name and then post what happens when you click the link? That's known as 'tailing the log' and it will give you real-time output of what's happening.
EDIT***
I looked at your code and I can see that at least one problem is the form you're using has:
<% provide(:title, 'Sign up') %>
<div style = "width: 200px; margin: 0 auto;">
<form action="form_action.asp" method="get">
<h1>Sign up</h1>
<p align="left">Name:</p>
<input type="text" name="fname" />
<p>Email:</p>
<input type="text" name="email" />
<p>Password:</p>
<input type="password" name="password" />
<p>Password Confirmation:</p>
<input type="password" name="password" />
<br/>
<input type="submit" value="Submit" />
</div>
</form>
There are a few errors in the form. First, the action is to form_action.asp. That looks like it came from an old project. Second, the end </div> and </form> tags are switched -- the form tag should be before the div tag.
<% provide(:title, 'Sign up') %>
<div style = "width: 200px; margin: 0 auto;">
<form action="form_action.asp" method="get">
<h1>Sign up</h1>
<p align="left">Name:</p>
<input type="text" name="fname" />
<p>Email:</p>
<input type="text" name="email" />
<p>Password:</p>
<input type="password" name="password" />
<p>Password Confirmation:</p>
<input type="password" name="password" />
<br/>
<input type="submit" value="Submit" />
</div>
</form>
It's likely that your local machine has different code on it than what you have deployed on Heroku. I'd check carefully -- do a heroku releases --app my-app and it will tell you what the latest git commit is on the server.

Resources