Inheritance: LoginRadiusEntityBase
コード例 #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");
        }
コード例 #2
0
 public ActionResult UpdateProfile(User user)
 {
     try
     {
         var userProfileData = (RaasUserprofile)Session["userprofile"];
         var _object = new LoginRadiusUserProfileEntity();
         var response = _object.UpdateUser(userProfileData.ID, user);
         UserProfiledata(System.Web.HttpContext.Current.Session["access_token"].ToString());
         return Content(response.isPosted ? "<script language='javascript' type='text/javascript'>alert( 'Profile has been updated !!' ); window.location.href ='/Home/Welcome'; </script>" : "<script language='javascript' type='text/javascript'>alert( 'Profile cannot be updated ,Please check parameters again !' ); window.location.href = '/Home/Welcome'; </script>");
     }
     catch (LoginRadiusException exception)
     {
         return Content("<script language='javascript' type='text/javascript'>alert( '" + exception.Response + "' ); window.location.href ='/Home/Welcome'; </script>");
     }
 }