예제 #1
0
        public ActionResult Register(string id)
        {
            ViewData["IsNew"] = false;

            if (string.IsNullOrEmpty(id))
            {
                id = AppUserState.UserId;
            }

            if (string.IsNullOrEmpty(id))
            {
                busUser.NewEntity();
                ViewData["IsNew"] = true;
            }
            else
            {
                if (id != AppUserState.UserId)
                {
                    return(RedirectToAction("Register", new { id = "" }));
                }

                if (busUser.Load(id) == null)
                {
                    return(RedirectToAction("LogOn", "Account", new { returnUrl = Url.Action("Register", "Account") }));
                }
            }

            return(View("Register", ViewModel));
        }
예제 #2
0
        public ActionResult UpdatePasswords()
        {
            var userBus = new busUser();

            foreach (var user in userBus.Context.Users)
            {
                userBus.Load(user.Id);
                userBus.Save(user);
            }

            ViewModel.ErrorDisplay.ShowMessage("User accounts have been updated.");
            return(View("Index", ViewModel));
        }
예제 #3
0
        public async Task <ActionResult> ExternalLinkLoginCallback()
        {
            // Handle external Login Callback
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, AppUserState.UserId);

            if (loginInfo == null)
            {
                IdentitySignout(); // to be safe we log out
                return(RedirectToAction("Register", new { message = "Unable to authenticate with external login." }));
            }

            // Authenticated!
            string providerKey  = loginInfo.Login.ProviderKey;
            string providerName = loginInfo.Login.LoginProvider;

            // Now load, create or update our custom user

            // normalize email and username if available
            if (string.IsNullOrEmpty(AppUserState.Email))
            {
                AppUserState.Email = loginInfo.Email;
            }
            if (string.IsNullOrEmpty(AppUserState.Name))
            {
                AppUserState.Name = loginInfo.DefaultUserName;
            }

            var  userBus = new busUser();
            User user    = null;

            if (!string.IsNullOrEmpty(AppUserState.UserId))
            {
                user = userBus.Load(AppUserState.UserId);
            }

            if (user == null && !string.IsNullOrEmpty(providerKey))
            {
                user = userBus.LoadUserByProviderKey(providerKey);
            }

            if (user == null && !string.IsNullOrEmpty(loginInfo.Email))
            {
                user = userBus.LoadUserByEmail(loginInfo.Email);
            }

            if (user == null)
            {
                user = userBus.NewEntity();
                userBus.SetUserForEmailValidation(user);
            }

            if (string.IsNullOrEmpty(user.Email))
            {
                user.Email = AppUserState.Email;
            }

            if (string.IsNullOrEmpty(user.Name))
            {
                user.Name = AppUserState.Name ?? "Unknown (" + providerName + ")";
            }


            if (loginInfo.Login != null)
            {
                user.OpenIdClaim = loginInfo.Login.ProviderKey;
                user.OpenId      = loginInfo.Login.LoginProvider;
            }
            else
            {
                user.OpenId      = null;
                user.OpenIdClaim = null;
            }

            // finally save user inf
            bool result = userBus.Save(user);

            // update the actual identity cookie
            AppUserState.FromUser(user);
            IdentitySignin(AppUserState, loginInfo.Login.ProviderKey);

            return(RedirectToAction("Register"));
        }
예제 #4
0
        public ActionResult New(FormCollection formValues)
        {
            ViewData["UserState"] = AppUserState;
            ViewData["languageList"] = this.GetLanguageList();

            busCodeSnippet busSnippet = new busCodeSnippet();
            CodeSnippet snippet = busSnippet.NewEntity();
            if (snippet == null)
            {
                ErrorDisplay.ShowError("Couldn't load snippet");
                return View(new CodeSnippet());
            }

            UpdateModel(snippet);                      

            if (!ValidateForSpam(snippet))
            {
                this.ErrorDisplay.ShowError("Invalid data posted back.");
                return View(snippet);
            }
            
            if (!busSnippet.Validate())
            {
                foreach (ValidationError error in busSnippet.ValidationErrors)
                {
                    this.ErrorDisplay.AddMessage(error.Message, error.ControlID);
                }
                this.ErrorDisplay.ShowError("Please correct the following:");
                return View(snippet);
            }

            // Assign the user from the authenticated user if any - otherwise blank
            // in which case the user can't edit entries.
            snippet.UserId = this.AppUserState.UserId;

            // 
            if (!string.IsNullOrEmpty(snippet.UserId))
            {
                var userBus = new busUser();
                var user = userBus.Load(snippet.UserId);
                if (user.InActive)
                {
                    ErrorDisplay.HtmlEncodeMessage = false;
                    ErrorDisplay.ShowError(
@"Your email address has not been validated yet so you
can't create posts for this account yet. Please click 
the following link and then check your email for a
message to validate your email.<br><br>
<a href='" +  Url.Content("~/Account/ResetEmailValidation") + 
"' target='emailreset'>Send Validation Request Email</a>");

                    return View(snippet);
                }
            }

            // strip of leading indentation always when capturing a new snippet
            snippet.Code = StringUtils.NormalizeIndentation(snippet.Code);                            
                       
            if (!busSnippet.Save())
            {
                this.ErrorDisplay.ShowError("Couldn't save snippet: " + busSnippet.ErrorMessage);
                return View(snippet);
            }

            return this.RedirectToAction("Show", new { id = busSnippet.Entity.Id });
        }
        public async Task<ActionResult> ExternalLinkLoginCallback()
        {
            // Handle external Login Callback
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, AppUserState.UserId);
            if (loginInfo == null)
            {
                IdentitySignout(); // to be safe we log out
                return RedirectToAction("Register", new {message = "Unable to authenticate with external login."});
            }

            // Authenticated!
            string providerKey = loginInfo.Login.ProviderKey;
            string providerName = loginInfo.Login.LoginProvider;

            // Now load, create or update our custom user

            // normalize email and username if available
            if (string.IsNullOrEmpty(AppUserState.Email))
                AppUserState.Email = loginInfo.Email;
            if (string.IsNullOrEmpty(AppUserState.Name))
                AppUserState.Name = loginInfo.DefaultUserName;

            var userBus = new busUser();
            User user = null;

            if (!string.IsNullOrEmpty(AppUserState.UserId))
                user = userBus.Load(AppUserState.UserId);

            if (user == null && !string.IsNullOrEmpty(providerKey))
                user = userBus.LoadUserByProviderKey(providerKey);

            if (user == null && !string.IsNullOrEmpty(loginInfo.Email))
                user = userBus.LoadUserByEmail(loginInfo.Email);

            if (user == null)
            {
                user = userBus.NewEntity();
                userBus.SetUserForEmailValidation(user);
            }

            if (string.IsNullOrEmpty(user.Email))
                user.Email = AppUserState.Email;

            if (string.IsNullOrEmpty(user.Name))
                user.Name = AppUserState.Name ?? "Unknown (" + providerName + ")";


            if (loginInfo.Login != null)
            {
                user.OpenIdClaim = loginInfo.Login.ProviderKey;
                user.OpenId = loginInfo.Login.LoginProvider;
            }
            else
            {
                user.OpenId = null;
                user.OpenIdClaim = null;
            }

            // finally save user inf
            bool result = userBus.Save(user);

            // update the actual identity cookie
            AppUserState.FromUser(user);
            IdentitySignin(AppUserState, loginInfo.Login.ProviderKey);

            return RedirectToAction("Register");
        }
예제 #6
0
        public ActionResult UpdatePasswords()
        {
            var userBus = new busUser();
            foreach (var user in userBus.Context.Users)
            {
                userBus.Load(user.Id);
                userBus.Save(user);
            }

            ViewModel.ErrorDisplay.ShowMessage("User accounts have been updated.");
            return View("Index",this.ViewModel);
        }
예제 #7
0
        public ActionResult New(FormCollection formValues)
        {
            ViewData["UserState"]    = AppUserState;
            ViewData["languageList"] = this.GetLanguageList();

            busCodeSnippet busSnippet = new busCodeSnippet();
            CodeSnippet    snippet    = busSnippet.NewEntity();

            if (snippet == null)
            {
                ErrorDisplay.ShowError("Couldn't load snippet");
                return(View(new CodeSnippet()));
            }

            UpdateModel(snippet);

            if (!ValidateForSpam(snippet))
            {
                this.ErrorDisplay.ShowError("Invalid data posted back.");
                return(View(snippet));
            }

            if (!busSnippet.Validate())
            {
                foreach (ValidationError error in busSnippet.ValidationErrors)
                {
                    this.ErrorDisplay.AddMessage(error.Message, error.ControlID);
                }
                this.ErrorDisplay.ShowError("Please correct the following:");
                return(View(snippet));
            }

            // Assign the user from the authenticated user if any - otherwise blank
            // in which case the user can't edit entries.
            snippet.UserId = this.AppUserState.UserId;

            //
            if (!string.IsNullOrEmpty(snippet.UserId))
            {
                var userBus = new busUser();
                var user    = userBus.Load(snippet.UserId);
                if (user.InActive)
                {
                    ErrorDisplay.HtmlEncodeMessage = false;
                    ErrorDisplay.ShowError(
                        @"Your email address has not been validated yet so you
can't create posts for this account yet. Please click 
the following link and then check your email for a
message to validate your email.<br><br>
<a href='" + Url.Content("~/Account/ResetEmailValidation") +
                        "' target='emailreset'>Send Validation Request Email</a>");

                    return(View(snippet));
                }
            }

            // strip of leading indentation always when capturing a new snippet
            snippet.Code = StringUtils.NormalizeIndentation(snippet.Code);

            if (!busSnippet.Save())
            {
                this.ErrorDisplay.ShowError("Couldn't save snippet: " + busSnippet.ErrorMessage);
                return(View(snippet));
            }

            return(this.RedirectToAction("Show", new { id = busSnippet.Entity.Id }));
        }