Exemplo n.º 1
0
        public ActionResult Welcome()
        {
            //Social Login Process.
            if (HttpContext.Request.Params["token"] != null)
            {
                var lrCallback = new LoginRadiusCallback();
                if (lrCallback.IsCallback)
                {
                    var accesstoken = lrCallback.GetAccessToken(WebConfigurationManager.AppSettings["loginradius:apisecret"]);
                    Session["access_token"] = accesstoken.access_token;
                    //create client with the help of access token as parameter
                    var client = new LoginRadiusClient(accesstoken);
                    //create object to execute user profile api to get user profile data.
                    var userprofile = new UserProfileApi();
                    //To get ultimate user profile data with the help of user profile api object as parameter.
                    // and pass "LoginRadiusUltimateUserProfile" model as interface to map user profile data.
                    var userProfileData = client.GetResponse<RaasUserprofile>(userprofile);
                    if (userProfileData != null)
                    {
                        Session["userprofile"] = userProfileData;
                        Session["Uid"] = userProfileData.Uid;
                        return View(userProfileData);
                    }
                    return Redirect("/Home/Index");
                }
            }

            //Traditional Login Process.
            else if (HttpContext.Request.Params["Access_token"] != null)
            {
                var userProfile = UserProfiledata(HttpContext.Request.Params["Access_token"]);
                return View(userProfile);
            }

            //Set Password and Traditional profile registration process for social user accounts.
            else if (HttpContext.Request.Params["password"] != null && HttpContext.Request.Params["confirmpassword"] != null && HttpContext.Request.Params["emailid"] != null)
            {
                var _object = new LoginRadiusAccountEntity();
                var userid = (string)System.Web.HttpContext.Current.Session["Uid"];
                _object.UserCreateRegistrationProfile(userid, HttpContext.Request.Params["emailid"], HttpContext.Request.Params["password"]);
                return Content("<script language='javascript' type='text/javascript'>alert('Password has been set !'); window.location.href =window.location.href;</script>");
            }

            //Process or Function to update password of user account.
            else if (HttpContext.Request.Params["oldpassword"] != null && HttpContext.Request.Params["newpassword"] != null && HttpContext.Request.Params["confirmnewpassword"] != null)
            {
                try
                {
                    var _object = new LoginRadiusUserProfileEntity();
                    _object.ChangePassword(HttpContext.Request.Params["raasid"], HttpContext.Request.Params["oldpassword"], HttpContext.Request.Params["newpassword"]);
                    return Content("<script language='javascript' type='text/javascript'>alert('Password has been Changed successfully !'); window.location.href =window.location.href;</script>");
                }
                //To catch loginRadius API exception.
                catch (LoginRadiusException)
                {
                    return Content("<script language='javascript' type='text/javascript'>alert('Password can not be updated, please check your old password!' ); window.location.href = window.location.href; </script>");
                }
            }

            //Process or Function to link  a social account.
            else if (HttpContext.Request.Params["accounttoken"] != null)
            {
                var accessToken = HttpContext.Request.Params["accounttoken"];
                var client = new LoginRadiusClient(accessToken);
                var userprofile = new UserProfileApi();
                var userProfileData = client.GetResponse<RaasUserprofile>(userprofile);
                var _object = new LoginRadiusAccountEntity();
                var userid = (string)System.Web.HttpContext.Current.Session["Uid"];
                try
                {
                    var status = _object.LinkAccount(userid, userProfileData.Provider, userProfileData.ID);
                    return Content(status.isPosted ? "<script language='javascript' type='text/javascript'>alert( 'Social Account has been linked !' ); window.location =window.location.href; </script>" : "<script language='javascript' type='text/javascript'>alert( 'Social Account can not be linked !' ); window.location =window.location.href; </script>");
                }
                catch (LoginRadiusException)
                {
                    return Content("<script language='javascript' type='text/javascript'>alert( 'Social Account cannot be linked! it has been linked with another account' ); window.location =window.location.href; </script>");
                }
            }

            //Process or Function to unlink a social account.
            else if (HttpContext.Request.Params["accountunlinkname"] != null && HttpContext.Request.Params["accountunlinkid"] != null)
            {
                try
                {
                    var _object = new LoginRadiusAccountEntity();
                    var userid = (string)System.Web.HttpContext.Current.Session["Uid"];
                    var status = _object.UnlinkAccount(userid, HttpContext.Request.Params["accountunlinkname"], HttpContext.Request.Params["accountunlinkid"]);
                    return Content(status.isPosted ? "<script language='javascript' type='text/javascript'>alert( 'Social Account has been unlinked !' ); window.location.href =window.location.href; </script>" : "<script language='javascript' type='text/javascript'>alert( 'Social Account can not be unlinked !' ); window.location.href = window.location.href; </script>");
                }
                catch (LoginRadiusException exception)
                {
                    return Content("<script language='javascript' type='text/javascript'>alert( '" + exception.Message + "' ); window.location.href ='/Home/Welcome'; </script>");
                }

            }
            return Redirect("/Home/Index");
        }
Exemplo n.º 2
0
 //Function to get Customer's profile data by Loginradius Access Token.
 public RaasUserprofile UserProfiledata(string accessToken)
 {
     Session["access_token"] = accessToken;
     //create client with the help of access token as parameter
     var client = new LoginRadiusClient(accessToken);
     //create object to execute user profile api to get user profile data.
     var userprofile = new UserProfileApi();
     //To get ultimate user profile data with the help of user profile api object as parameter.
     // and pass "LoginRadiusUltimateUserProfile" model as interface to map user profile data.
     var userProfileData = client.GetResponse<RaasUserprofile>(userprofile);
     if (userProfileData == null) { return null; }
     Session["userprofile"] = userProfileData;
     Session["Uid"] = userProfileData.Uid;
     return userProfileData;
 }