I am getting a blank page instead of errors. and also my session variables are not working.
function login(){
$uname=$this->input->post('uname');
$upass=$this->input->post('upass');
$login_status=$this->Loginmodel->logincheck($uname,$upass);
if ($login_status) {
$this->session->set_userdata('logintrue', '1122');
$this->session->set_userdata('username', $uname);
redirect(base_url()."FT_admin/Home", '');
} else
{
$data['title']="Ftre | Admin-Home";
$data['Error']="Invalid detaisl";
$this->load->view('admin/A_header',$data);
$this->load->view('admin/A_login',$data);
$this->load->view('admin/A_footer',$data);
}
}
Related
I have /logout action, that should redirect to /login. /login renders template, where I read flash message from context. This works, but url in browser is still remains "/logout":
router.get("/logout").handler((ctx) => {
if (ctx.user()!=null) {
ctx.clearUser()
//flash message
ctx.put("msg", "Logout succeed")
}
ctx.reroute("/login")
})
What I want, but url should be "/login":
Better to use(?):
ctx.response.putHeader("location", "/login").setStatusCode(302).end()
But there is different context. So I haven't flash message.
How to redirect to /login within same context?
Upd.
Question related to this issue
In order to work with flash messages you should add a cookie to the redirect with the content:
// this makes the message available to the client
ctx
.addCookie(Cookie.cookie("flashMessage", "Logout succeed"));
// configure where to redirect
ctx.response()
.putHeader("location", "/login");
// perform the redirect
ctx.end(302);
Then on the client side you need a bit of JavaScript to read the message and
perform the display as you wish. Since there is no simple way to read cookies on the browser if you're using jQuery with the cookie plugin you can do something like:
$.fn.flashMessage = function (options) {
var target = this;
options = $.extend({}, options, { timeout: 3000 });
if (!options.message) {
options.message = getFlashMessageFromCookie();
deleteFlashMessageCookie();
}
if (options.message) {
if (typeof options.message === "string") {
target.html("<span>" + options.message + "</span>");
} else {
target.empty().append(options.message);
}
}
if (target.children().length === 0) return;
target.fadeIn().one("click", function () {
$(this).fadeOut();
});
if (options.timeout > 0) {
setTimeout(function () { target.fadeOut(); }, options.timeout);
}
return this;
function getFlashMessageFromCookie() {
return $.cookie("FlashMessage");
}
function deleteFlashMessageCookie() {
$.cookie("FlashMessage", null, { path: '/' });
}
};
And add a placeholder in your HTML like:
<div id="flash-message"></div>
And trigger it like:
$(function() {
$("#flash-message").flashMessage();
});
I have tried every way I can think and am running into the same issue all day.
I am building a react native mobile application. I am using firebase as my database and react-native-facebook-login package to log the user in.
Currently the package works fine, I enter the fb details and the correct data is being returned and the user is 'logged in', I can console log the result but trying to do anything else returns an error.
I have tried:
Passing an action (Redux) where I do the firebase login, error:
Cannot read property 'loginUser' of undefined
setState to the resulting data, error:
this.setState is not a function
I am not sure exactly how to do the firebase authenticate with credentials but am happy to figure that out later, I just need to be able to access the data in the first place!
My component:
...
class FBLoginWrapper extends Component {
state = { user: null };
render() {
return (
<FBLogin
buttonView={<FBSignInView />}
ref={(fbLogin) => { this.fbLogin = fbLogin }}
loginBehavior={FBLoginManager.LoginBehaviors.Native}
permissions={["email","user_friends"]}
onLogin={function (e) { this.props.loginUser(e); }}
onLoginFound={function (e) { this.setState({ user: e }); }}
/>
);
}
...
If you need more code let me know. I have included two different ways I have tried and failed under [onLogin] and [onLoginFound]. I will use one implementation for both when I have something that works.
Ideally I would like to call the action {this.props.loginUser(e)} but if I have to do it through a setState that is fine too at this point.
you should use the onLoginFinished property if you just need to access the data returned.
This is how I use the LoginButton in one of my apps:
AccessToken is part of the FBSDK package
const FBSDK = require('react-native-fbsdk');
const {
LoginButton,
AccessToken
} = FBSDK;
....
<View>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
let token = data.accessToken.toString();
global.storage.save({
key: 'loginState',
rawData: {
token: token
},
});
firestack.auth.signInWithProvider('facebook', token, '')
.then((user)=>{
Actions.tabbar({profile:user});
});
}
)
}
}
}
onLogoutFinished={() => alert("logout.")}/>
I am trying to make a login redirect using the following code:
Router.onBeforeAction(function () {
if (!Meteor.user() && !Meteor.loggingIn()) {
this.next();
} else {
// required by Iron to process the route handler
this.redirect('/map');
this.next();
}
});
But, when I login and it successfully redirects me to /maps, I can't click any of my link on my navbar. The link are working fine, but, when I click on them it just redirects me back to /map.
Help will be much appreciated!
Also, here is the github link:
https://github.com/Aggr0vatE/testbasichelp
What about this:
Router.route('/login',
{ name: 'login' });
var requireLogin = function(){
if (! Meteor.user() ) {
this.redirect('login');
} else {
this.next();
}
}
Router.onBeforeAction(requireLogin, {except: ['login']});
I am getting error on facebook login on my web site.
i am getting this error: sdk.ErrorHandling
when i remove function of login it works perfectly, i think i have some problem in login function.
can any one please help me how to write login function of facebook
here is my code:
function login() {
oldToken = FB.getAccessToken();
FB.login(function (response) {
if (response.authResponse && response.authResponse.accessToken != oldToken) {
if (fbdone == false) {
GetUserData();
fbdone = true;
}
}
}, {
auth_type: 'reauthenticate', scope: 'email,user_friends,public_profile'
});
and this error i am getting
sdk.ErrorHandling",["ManagedError","sdk.Runtime","sdk.Scribe","sdk.UA","sdk.feature","wrapFunction"],function(a,b,c,d,e,f,g,h,i,j,k,l){b.__markCompiled&&b.__markCompiled();var m=k('error_handling',false),n='';function o(u){var v=u._originalError;delete u._originalError;i.log('jssdk_error',{appId:h.getClientID(),error:u.name||u.message,extra:u});throw v;}function p(u){var v={line:u.lineNumber||u.line,message:u.message,name:u.name,script:u.fileName||u.sourceURL||u.script,stack:u.stackTrace||u.stack};v._originalError=u;if(j.chrome()&&/([\w:\.\/]+\.js):(\d+)/.test(u.stack)){v.script=RegExp.$1;v.line=parseInt(RegExp.$2,10);}for(var w in v)(v[w]==null&&delete v[w]);return v;}function q(u,v){return function(){if(!m)return u.apply(this,arguments);try{n=v;return u.apply(this,arguments);}catch(w){if(w instanceof g)throw w;var x=p(w);x.entry=v;var y=ES(Array.prototype.slice.call(arguments),'map',true,function(z){var aa=Object.prototype.toString.call(z);return (/^\[object (String|Number|Boolean|Object|Date)\]$/).test(aa)?z:z.toString();});x.args=ES('JSON','stringify',false,y).substring(0,200);o(x);}finally{n='';}};}function r(u){if(!u.__wrapper)u.__wrapper=function(){try{return u.apply(this,arguments);}catch(v){window.setTimeout(function(){throw v;},0);return false;}};return u.__wrapper;}function s(u,v){return function(w,x){var y=v+':'+(n||'[global]')+':'+(w.name||'[anonymous]'+(arguments.callee.caller.name?'('+arguments.callee.caller.name+')':''));return u(l(w,'entry',y),x);};}if(m){setTimeout=s(setTimeout,'setTimeout');setInterval=s(setInterval,'setInterval');l.setWrapper(q,'entry');}var t={guard:q,unguard:r};e.exports=t;},null);
i'm currently trying to migrate my site to yii. (still new to it too) in my site i have a facebook login code that looks like this
function updateButton(response) {
var b = document.getElementById("{$this->fbLoginButtonId}");
b.onclick = function(){
$("#{$this->fbLoginButtonId}").button("loading");
FB.login(function(response) {
if(response.authResponse) {
$('#processing').modal({show: true, backdrop: 'static', keyboard: false});
FB.api('/me', function(user) {
$.ajax({ type : 'post'
, url: '{$this->facebookLoginUrl}'
, data: ({ user: user })
, dataType: 'json'
, success: function(data){
if(data.error == 0){
window.location.href = data.success;
} else {
$('#processing').modal('hide');
showError(data.error);
$("#{$this->fbLoginButtonId}").button("reset");
}
}
});
});
} else { $("#{$this->fbLoginButtonId}").button("reset"); }
}, {scope: '{$this->facebookPermissions}'});
}
}
the line url: '{$this->facebookLoginUrl}' basically points to the file that does the authentication. in Yii, i put that file in protected/controllers/facebookcontroller.php
class FacebookController extends Controller {
public $defaultAction = 'facebook';
public function actionFacebook() {
if (app()->request->isAjaxRequest) {
$user = app()->request->getParam('user');
Shared::debug($user);
// verify one last time that facebook knows this guy
if($user['id'] === app()->facebook->getUser()){
$model = User::model()->findByEmail($user['email']);
if(!empty($model)){
// facebook email matches one in the user database
$identity = new UserIdentity( $model->email , null );
$identity->_ssoAuth = true;
$identity->authenticate();
if($identity->errorCode === UserIdentity::ERROR_NONE){
app()->user->login($identity, null);
echo json_encode(array('error' => false, 'success' => url('/')));
app()->end();
} else {
echo json_encode(array('error' => 'System Authentication Failed', 'code' => 'auth'));
app()->end();
}
} else {
// nothing found, this person should register
// write query to input into database!!!
}
} else {
// fb user id past from ajax does not match who facebook says they are...
echo json_encode(array('error' => 'Facebook Authentication Failed', 'code' => 'fb_auth'));
app()->end();
}
} else {
throw new CHttpException(403);
}
}
}
basically what do i put here url: '{$this->facebookLoginUrl}' ?? i tried http://localhost/facebook.html but doesn't work. i get this error on firebug
<h1>PHP Error [8]</h1>
<p>Undefined index: email (/Applications/XAMPP/xamppfiles/htdocs/protected/controllers/FacebookController.php:13)</p>
<pre>#0 /Applications/XAMPP/xamppfiles/htdocs/protected/controllers/FacebookController.php(13): CWebApplication->handleError()
#1 /Applications/XAMPP/xamppfiles/htdocs/yii/web/actions/CInlineAction.php(49): FacebookController->actionFacebook()
#2 /Applications/XAMPP/xamppfiles/htdocs/yii/web/CController.php(308): CInlineAction->runWithParams()
#3 /Applications/XAMPP/xamppfiles/htdocs/yii/web/CController.php(286): FacebookController->runAction()
#4 /Applications/XAMPP/xamppfiles/htdocs/yii/web/CController.php(265): FacebookController->runActionWithFilters()
#5 /Applications/XAMPP/xamppfiles/htdocs/yii/web/CWebApplication.php(282): FacebookController->run()
#6 /Applications/XAMPP/xamppfiles/htdocs/yii/web/CWebApplication.php(141): CWebApplication->runController()
#7 /Applications/XAMPP/xamppfiles/htdocs/yii/base/CApplication.php(180): CWebApplication->processRequest()
#8 /Applications/XAMPP/xamppfiles/htdocs/index.php(25): CWebApplication->run()
</pre>
the ajax post response looks like this..
user[birthday] MM/DD/YYYY
user[first_name] name
user[gender] male
user[hometown][id] 106031246101856
user[hometown][name] CITY, STATE
user[id] 598482999
user[last_name] LASTNAME
user[link] https://www.facebook.com/ID
user[locale] en_US
user[location][id] 106031246101856
user[location][name] CITY, STATE
user[middle_name] MIDDLENAME
user[name] FULLNAME
user[timezone] -8
user[updated_time] 2013-12-15T16:43:03+0000
user[username] USERNAME
user[verified] true
Yii generates url as http://www.example.com/index.php?r={controller_id}/{action_id}.
So in your case url will be http://www.example.com/index.php?r=facebook/facebook.
Learn how yii manges url's here.