Пример #1
0
        private void OnLoginClick(object sender, EventArgs e)
        {
            ///TRY TO LOGIN WITH WS
            var result = Innovaction.WSManager.ValidateLogin(txtUsername.Text, txtPassword.Text);

            if (result.responseCode.ToString() == Innovaction.CustomerDataWS.responseCode.SUCCESS.ToString())
            {
                /****** CREATE USER ******/

                //We create the new user in the portal, even if it exists we don't care
                UserInfo newUser = new UserInfo();
                newUser.Username            = txtUsername.Text;
                newUser.PortalID            = PortalId;
                newUser.DisplayName         = txtUsername.Text;
                newUser.Email               = txtUsername.Text;
                newUser.FirstName           = txtUsername.Text;
                newUser.LastName            = txtUsername.Text;
                newUser.Membership.Password = txtPassword.Text;
                //newUser.Profile.SetProfileProperty("tel", "47940983");

                //The line that creates the new User
                DotNetNuke.Security.Membership.UserCreateStatus userResult = DotNetNuke.Entities.Users.UserController.CreateUser(ref newUser);


                /****** LOGIN USER AT THE PORTAL ******/

                var myUser = DotNetNuke.Entities.Users.UserController.GetUserByName(txtUsername.Text);                 // IF WE USE THIS WE CAN LOGIN WITHOUT PASSWORD
                DotNetNuke.Entities.Users.UserController.UserLogin(PortalId, myUser, PortalSettings.PortalName, "", false);

                //try to redirect
                string myReturnUrl = "";
                try
                {
                    myReturnUrl = System.Web.HttpContext.Current.Request.QueryString["returnurl"].ToString();
                }
                catch
                {
                }

                if (myReturnUrl != "")
                {
                    string unescapedUrl = System.Uri.UnescapeDataString(myReturnUrl);
                    System.Web.HttpContext.Current.Response.Redirect(unescapedUrl);
                }

                else
                {
                    System.Web.HttpContext.Current.Response.Redirect("/");
                }



                /*
                 * var eventArgs = new UserAuthenticatedEventArgs(myUser, txtUsername.Text, UserLoginStatus.LOGIN_SUCCESS, "DNN")
                 *                                              {
                 *                                                      Authenticated = True,
                 *                                                      Message = "",
                 *                                                      RememberMe = False
                 *                                              };
                 *
                 *      OnUserAuthenticated(eventArgs);
                 *
                 * //System.Web.HttpContext.Current.Response.Redirect("http://www.bspdota.com.ar/hola?=" + "1.0.1" + result.responseCode.ToString());
                 */
            }

            else             ///ELSE TRY WITH DOTNETNUKE
            {
                if ((UseCaptcha && ctlCaptcha.IsValid) || !UseCaptcha)
                {
                    var loginStatus   = UserLoginStatus.LOGIN_FAILURE;
                    var objUser       = UserController.ValidateUser(PortalId, txtUsername.Text, txtPassword.Text, "DNN", string.Empty, PortalSettings.PortalName, IPAddress, ref loginStatus);
                    var authenticated = Null.NullBoolean;
                    var message       = Null.NullString;
                    if (loginStatus == UserLoginStatus.LOGIN_USERNOTAPPROVED)
                    {
                        message = "UserNotAuthorized";
                    }
                    else
                    {
                        authenticated = (loginStatus != UserLoginStatus.LOGIN_FAILURE);
                    }

                    //Raise UserAuthenticated Event
                    var eventArgs = new UserAuthenticatedEventArgs(objUser, txtUsername.Text, loginStatus, "DNN")
                    {
                        Authenticated = authenticated,
                        Message       = message,
                        RememberMe    = chkCookie.Checked
                    };
                    OnUserAuthenticated(eventArgs);
                }
            }
        }
Пример #2
0
        public HttpResponseMessage Users_Update([FromBody] string _json_content)
        {
            int v_Current_Portal_ID  = this.ActiveModule.PortalID;
            HttpResponseMessage resp = new HttpResponseMessage();

            Entities.User_Info v_Received_User = Newtonsoft.Json.JsonConvert.DeserializeObject <Entities.User_Info>(_json_content, new Newtonsoft.Json.Converters.IsoDateTimeConverter {
                DateTimeFormat = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern
            });

            Entities.User_Update_Result v_Update_Result = new Entities.User_Update_Result();

            if (v_Received_User.UserID > 0)
            {
                DotNetNuke.Entities.Users.UserInfo v_DNN_UserInfo;
                v_DNN_UserInfo = DotNetNuke.Entities.Users.UserController.GetUserById(v_Current_Portal_ID, v_Received_User.UserID);

                if (v_DNN_UserInfo != null)
                {
                    v_DNN_UserInfo.Email       = v_Received_User.Email;
                    v_DNN_UserInfo.FirstName   = v_Received_User.FirstName;
                    v_DNN_UserInfo.LastName    = v_Received_User.LastName;
                    v_DNN_UserInfo.DisplayName = v_Received_User.DisplayName;
                    v_DNN_UserInfo.Username    = v_Received_User.Username;

                    DotNetNuke.Entities.Users.UserController.UpdateUser(v_Current_Portal_ID, v_DNN_UserInfo);

                    v_Update_Result.errorMessage = "updateok";
                    v_Update_Result.UserID       = v_Received_User.UserID;
                }
            }
            else
            {
                //Creating new user
                DotNetNuke.Entities.Users.UserInfo v_DNN_UserInfo = new UserInfo();

                v_DNN_UserInfo.Email       = v_Received_User.Email;
                v_DNN_UserInfo.FirstName   = v_Received_User.FirstName;
                v_DNN_UserInfo.LastName    = v_Received_User.LastName;
                v_DNN_UserInfo.DisplayName = v_Received_User.DisplayName;
                v_DNN_UserInfo.Username    = v_Received_User.Username;
                v_DNN_UserInfo.PortalID    = v_Current_Portal_ID;

                v_DNN_UserInfo.Profile.PreferredLocale   = DotNetNuke.Services.Localization.LocaleController.Instance.GetCurrentLocale(v_Current_Portal_ID).Code;
                v_DNN_UserInfo.Profile.PreferredTimeZone = TimeZoneInfo.Local;
                v_DNN_UserInfo.Profile.FirstName         = v_Received_User.FirstName;
                v_DNN_UserInfo.Profile.LastName          = v_Received_User.LastName;

                v_DNN_UserInfo.Membership.Password    = v_Received_User.Password;
                v_DNN_UserInfo.Membership.Approved    = true;
                v_DNN_UserInfo.Membership.CreatedDate = DateTime.Now;

                DotNetNuke.Security.Membership.UserCreateStatus v_CreateResult = DotNetNuke.Entities.Users.UserController.CreateUser(ref v_DNN_UserInfo);
                if (v_CreateResult != DotNetNuke.Security.Membership.UserCreateStatus.Success)
                {
                    v_Update_Result.errorMessage = v_CreateResult.ToString();
                    v_Update_Result.UserID       = v_DNN_UserInfo.UserID;
                }
                else
                {
                    //Updating profile data (needed for First name, Last name...)
                    v_DNN_UserInfo = UserController.GetUserById(v_Current_Portal_ID, v_DNN_UserInfo.UserID);
                    v_DNN_UserInfo.Profile.PreferredLocale   = DotNetNuke.Services.Localization.LocaleController.Instance.GetCurrentLocale(v_Current_Portal_ID).Code;
                    v_DNN_UserInfo.Profile.PreferredTimeZone = TimeZoneInfo.Local;
                    v_DNN_UserInfo.Profile.FirstName         = v_Received_User.FirstName;
                    v_DNN_UserInfo.Profile.LastName          = v_Received_User.LastName;
                    UserController.UpdateUser(v_Current_Portal_ID, v_DNN_UserInfo);

                    v_Update_Result.errorMessage = "creationok";
                    v_Update_Result.UserID       = v_DNN_UserInfo.UserID;
                }
            }


            return(Request.CreateResponse(HttpStatusCode.OK, Newtonsoft.Json.JsonConvert.SerializeObject(v_Update_Result)));
        }