コード例 #1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            string msg = null;

            if (ModelState.IsValid)
            {
                int retcode = MembershipService.LogON(model.Login, model.Password, out msg);
                switch (retcode)
                {
                case 0:
                {
                    FormsService.SignIn(model.Login, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                case 1:
                    FormsService.SignIn(model.Login, model.RememberMe);
                    return(RedirectToAction("ChangePassword"));

                default:
                    ModelState.AddModelError("", msg);
                    return(View(model));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "El usuario o contraseña ingresado se encuentra incorrecto.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #3
0
        public ActionResult Register(RegisterModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
        }
コード例 #4
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "提供的用户名或密码不正确。");
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
コード例 #5
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #6
0
        public virtual ActionResult Create(Customer customer)
        {
            MembershipCreationStatus membershipCreationStatus = MembershipService.Create(customer);

            if (membershipCreationStatus == MembershipCreationStatus.Success)
            {
                // Si no está logueado
                if (String.IsNullOrEmpty(User.Identity.Name))
                {
                    FormsService.SignIn(customer.Email, false);
                    TempData["Message"] = "Tu cuenta ha sido creada con éxito, ya podés comenzar a operar con Hope!";
                }
                else // Si ya está logueado
                {
                    FormsService.SignOut();
                    TempData["Message"] = "Tu cuenta ha sido creada con éxito, ingesá al sitio y comenzá a operar con Hope!";
                }

                TempData["ActionType"] = ActionType.Catalogue;
            }

            if (membershipCreationStatus == MembershipCreationStatus.DuplicateEmail)
            {
                TempData["Message"]    = "Ya existe una cuenta con el E-mail ingresado!";
                TempData["ActionType"] = ActionType.Back;
            }

            if (membershipCreationStatus == MembershipCreationStatus.Fail)
            {
                TempData["Message"]    = "Ha ocurrido un error al crear su usuario!";
                TempData["ActionType"] = ActionType.Back;
            }

            return(RedirectToAction("Information"));
        }
コード例 #7
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Le nom d'utilisateur et/ou le mot de passe est incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #8
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var db = DB.Entities;
                // Attempt to register the user
                if (db.mUser.FirstOrDefault(m => m.UserName.Equals(model.UserName)) == null)
                {
                    MembershipUser aspnetUser  = Membership.CreateUser(model.UserName, model.Password, model.Email);
                    Guid           userCreated = (Guid)aspnetUser.ProviderUserKey;
                    if (userCreated != null)
                    {
                        db.mUser.AddObject(new mUser()
                        {
                            UserName = model.UserName, Email = model.Email, PhoneNumber = model.Phone, Address = model.Address, AspnetUserID = userCreated, Name = model.Name
                        });
                        db.SaveChanges();
                        FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Register unsuccesfully!");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Tài khoản đã tồn tại!");
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
        }
コード例 #9
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.txtCode == StringCipher.Decrypt(model.hdnCode.ToString(), model.Email.ToString() + "A123b789"))
                {
                    // Attempt to register the user
                    MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsService.SignIn(model.UserName, true /* createPersistentCookie */);


                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
コード例 #10
0
ファイル: AccountController.cs プロジェクト: DCT-UA/Monator
        public ActionResult LogOnUsingOpenId(string site)
        {
            var locatedUser = ProvidersLocator.LocateService();

            if (locatedUser != null)
            {
                var id = locatedUser.Identifier;
                if (!String.IsNullOrEmpty(id))
                {
                    Session.User = new User();
                    Session.User.ProviderUserId = id;
                    Session.User.ProviderId     = (int)locatedUser.Provider.Id;
                    var identifier = userModule.GetUserByProviderUserId(id);
                    if (identifier != null)
                    {
                        Session.User.Id = identifier.Id;
                        Session.User    = userModule.GetUser(identifier.UserName);

                        ViewData["UserName"] = Session.User.UserName;
                        FormsService.SignIn(identifier.UserName, false);
                        Session.SessionEndTime = DateTime.Now;
                        return(Redirect(Url.Home()));
                    }
                    else
                    {
                        ViewData["ProviderId"] = id;
                        return(Redirect(Url.Register(), true));
                    }
                }
            }

            switch (site)
            {
            case "twitter":
                var client = new TwitterClient(ProvidersLocator.TwitterTokenManager);
                client.StartAuthentication(Request.Url);
                break;

            case "google":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.Google.EndPoint);
                break;

            case "vkontakte":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.VKontakte.EndPoint);
                break;

            case "linkedin":
                var authorization = new WebOAuthAuthorization(ProvidersLocator.LinkedinTokenManager, null);
                var callback      = Request.Url;
                authorization.BeginAuthorize(callback);
                break;

            case "myspace":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.MySpace.EndPoint);
                break;
            }

            ViewData.Model = new AccountModel(new LogOnModel());
            return(View("LogOn"));
        }
コード例 #11
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = new UserDAL().GetUserByUserName(model.UserName);
                if (user != null && !user.Locked)
                {
                    if (MembershipService.ValidateUser(model.UserName, model.Password))
                    {
                        FormsService.SignIn(model.UserName, model.RememberMe);
                        ListFunctionCode = new UserDAL().GetListFunctionCodeByUsername(model.UserName);
                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "DriverInfo"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Username or password incorrect.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Username or password incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #12
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    TinyLibraryServiceClient svcClient = new TinyLibraryServiceClient();
                    bool ret = svcClient.AddReader(new ReaderData
                    {
                        Id       = Guid.NewGuid(),
                        Name     = model.Name,
                        UserName = model.UserName
                    });
                    svcClient.Close();
                    if (ret)
                    {
                        FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                    }
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
コード例 #13
0
 public ActionResult Login(string username, string password, bool rememberMe)
 {
     try
     {
         if (MembershipService.ValidateUser(username, password))
         {
             FormsService.SignIn(username, rememberMe);
         }
         else
         {
             ViewBag.Error = "Username ou password incorrect";
             return(View("Login"));
         }
     }
     catch (ArgumentException e)
     {
         ViewBag.Error = "Veuillez remplir les champs correctement";
         return(View("Login"));
     }
     catch (Exception e)
     {
         return(RedirectToAction("Problem", "Error", null));
     }
     return(RedirectToAction("Index", "Home", null));
 }
コード例 #14
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Profile", "Home"));
                    }
                }
                else
                {
                    // Has the user locked themselves out? if so inform them.
                    MembershipUser membershipUser = Membership.GetUser(model.UserName);
                    if (membershipUser != null && membershipUser.IsLockedOut)
                    {
                        TempData["errorMessage"] = "The account " + model.UserName + " is currenly in locked out state. Please contact your administrator.";
                        return(View(model));
                    }

                    TempData["errorMessage"] = "The username or password provided is incorrect. Please try again.";
                    return(View(model));
                    // ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #15
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            // AuthenticationMgr authMgr = new AuthenticationMgr();
            // AuthenticationServiceClient client = new AuthenticationServiceClient();
            AuthenticationService client = new AuthenticationService();  //webservice client

            if (ModelState.IsValid)
            {
                if (client.isValidCredentials(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "We are sorry, but the username and password entered is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #16
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "所提供的使用者名稱或密碼不正確。");
                }
            }

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            return(View(model));
        }
コード例 #17
0
        public virtual ActionResult LogOn(FormCollection formCollection, string returnUrl)
        {
            string email    = formCollection["Email"];
            string password = formCollection["Password"];
            string action   = string.Empty;
            bool   isValid  = false;

            isValid = MembershipService.Validate(email, password);

            if (isValid)
            {
                FormsService.SignIn(email, false);

                if (!String.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Edit"));
                }
            }

            TempData["Message"]    = "El Email o la clave ingresada no son correctos!";
            TempData["ActionType"] = ActionType.Back;

            return(Redirect("/Account/Information"));
        }
コード例 #18
0
 public ActionResult RegisterNewUser(User usuario)
 {
     if (ModelState.IsValid)
     {
         // Attempt to register the user
         var user = new CustomMembershipUser("CustomMembershipProvider",
                                             usuario.UserName,
                                             usuario.Id,
                                             usuario.Email,
                                             "",
                                             "",
                                             true,
                                             false,
                                             usuario.CreateDate,
                                             DateTime.Now,
                                             DateTime.Now,
                                             DateTime.Now,
                                             DateTime.Now)
         {
             User = usuario
         };
         var createStatus = MembershipService.CreateUser(user);
         if (createStatus == MembershipCreateStatus.Success)
         {
             FormsService.SignIn(user.UserName, false /* createPersistentCookie */);
             return(RedirectToAction("Index", "UserManagement"));
         }
         ModelState.AddModelError("", ErrorCodes.ErrorCodeToString(createStatus));
     }
     // If we got this far, something failed, redisplay form
     return(View(usuario));
 }
コード例 #19
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, false);
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "O nome de usuário ou senha fornecida está incorreta.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #20
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Имя пользователя или пароль указаны неверно.");
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
コード例 #21
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    ServiceAvailability.Reload();
                    Log.Debug("User {0} logged in from host {1}", model.UserName, Request.UserHostAddress);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", FormStrings.UsernamePasswordIncorrect);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #22
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "El nombre de usuario o la contraseña especificados son incorrectos.");
                }
            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            return(View(model));
        }
コード例 #23
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Use a transaction
                //using (System.Transactions.TransactionScope trans = new System.Transactions.TransactionScope())
                //{
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    // Register user in the SimpleList database
                    var userRepository = new UserRepository();
                    var user           = new User {
                        Name = model.UserName, Password = model.Password, Email = model.Email
                    };
                    userRepository.AddUser(user);
                    //trans.Complete();

                    // Sign the new user in, final step before closing the transaction
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
                //}
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
コード例 #24
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(new ContentResult {
                            Content = returnUrl
                        });
                    }
                    var helper = new UrlHelper(ControllerContext.RequestContext);
                    var url    = helper.Action("Index", "Home");
                    return(new ContentResult {
                        Content = url
                    });
                }
            }

            return(new ContentResult {
                Content = "<span>The user name or password provided is incorrect.<span>"
            });
        }
コード例 #25
0
ファイル: AccountController.cs プロジェクト: zfaustk/Yiku
        public ActionResult LogIn(LogOnModel model, string returnUrl)
        {
            ViewData["ErrorMessage"] = "";
            if (yikuData.UserCurrent == null)
            {
                if (model.UserName == null || model.Password == null)
                {
                    ModelState.AddModelError("", "提供的用户名或密码不正确。");
                    return(View(model));
                }

                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "提供的用户名或密码不正确。");
                }
            }

            ViewData["ErrorMessage"] = "提供的用户名或密码不正确。";
            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
コード例 #26
0
        public ActionResult ActivateAccount(string id)
        {
            if (Session["ACTIVATED_USER"] != null)
            {
                return(View());
            }

            ViewBag.RegionId = new SelectList(market.Regions, "Id", "Name");
            var user = market.Users.SingleOrDefault(u => u.ActivationId == id);

            if (user != null)
            {
                if (user.isFacebookUser == true)
                {
                    if (user.FacebookProfile.IsApproved == false)
                    {
                        FacebookClient fbClient = new FacebookClient(user.FacebookProfile.AccessToken);
                        dynamic        me       = fbClient.Get("me");
                        user.FirstName = (string)me.first_name;
                        user.LastName  = (string)me.last_name;
                        user.FacebookProfile.IsApproved = true;
                        market.Entry(user).State        = EntityState.Modified;
                        market.SaveChanges();
                        FormsService.SignIn(user.Email, false /* createPersistentCookie */);
                        Session["USER_F_NAME"] = user.FirstName;
                        log.Info("Account - User account activated (" + user.Email + ")");
                    }
                    Session["ACTIVATED_USER"] = true;
                    return(RedirectToAction("ActivateAccount", new { id = id }));
                }

                MembershipUser RegisteredUser = Membership.GetUser(user.Email);

                if (RegisteredUser.IsApproved == false)
                {
                    if (user.FirstName == "Rambla" && user.LastName == "User")
                    {
                        var model = new RegisterModel
                        {
                            Email = user.Email
                        };
                        return(View(model));
                    }
                    //RegisteredUser.pa
                    RegisteredUser.IsApproved = true;
                    Membership.UpdateUser(RegisteredUser);
                    FormsService.SignIn(user.Email, false /* createPersistentCookie */);
                    Session["USER_F_NAME"]    = user.FirstName;
                    Session["ACTIVATED_USER"] = true;
                    log.Info("Account - User account activated (" + user.Email + ")");
                    return(RedirectToAction("ActivateAccount", new { id = id }));
                }
            }
            else
            {
                log.Error("Account - Invalid activation ID (" + id + ")");
            }
            return(RedirectToAction("Index", "Home"));
        }
コード例 #27
0
        public ActionResult LogIn(LogInModel model, string returnUrl)
        {
            IUserContext userContext;

            if (ModelState.IsValid)
            {
                userContext = CoreData.UserManager.Login(model.UserName, model.Password, Resources.DyntaxaSettings.Default.DyntaxaApplicationIdentifier);

                if (userContext.IsNotNull())
                {
                    Session["userContext"] = userContext;

                    // Must clear the service cash so that roles can be reloded.
                    // CoreData.TaxonManager.ClearCacheForUserRoles(userContext);                    
                 //   _sessionHelper.SetInSession("userContext", userContext);

                     /* globalization with cookie */
                    var cookie = Request.Cookies["CultureInfo"];
                    
                    if (cookie == null)
                    {
                        var locale = CoreData.LocaleManager.GetUsedLocales(GetCurrentUser()).Get(userContext.Locale.ISOCode);
                        SetLanguage(locale.ISOCode);
                    }
                    else
                    {
                        if (cookie.Value != null)
                        {
                            var locale = CoreData.LocaleManager.GetUsedLocales(GetCurrentUser()).Get(cookie.Value);
                            userContext.Locale = locale;
                        }
                    }

                    //HttpCookie cookie = new HttpCookie("CultureInfo");
                    //cookie.Value = userContext.Locale.ISOCode;
                    //cookie.Expires = DateTime.Now.AddYears(1);
                    //Response.Cookies.Add(cookie);

                    FormsService.SignIn(model.UserName);
                    this.RedrawTree();
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        //TempData.Add("RedirectedFromLogin", true);
                        return Redirect(returnUrl.ToLower());
                    }
                    else
                    {
                        return RedirectToAction("SearchResult", "Taxon");
                    }
                }
                else
                {
                    ModelState.AddModelError("", Resources.DyntaxaResource.AccountControllerIncorrectLoginError);
                }
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #28
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                List <Usuario> listaUsuarios = null;
                var            usuarios      = (from u in _data.TB_Usuarios
                                                join c in _data.TB_Clientes
                                                on u.Fk_eCliente equals c.Pk_eCliente
                                                where u.cUsuario == model.UserName && u.cContrasena == model.Password
                                                select new
                {
                    u.Pk_eUsuario,
                    u.cUsuario,
                    u.cContrasena
                }).ToList();

                listaUsuarios = usuarios.ConvertAll(o => new Usuario(o.Pk_eUsuario, o.cUsuario, o.cContrasena));

                if (listaUsuarios.Count > 0)
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("RealizarCompra", "CarritoCompras"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "El nombre de usuario o clave ingresados no son correctos.");
                }


                //if (MembershipService.ValidateUser(model.UserName, model.Password))
                //{
                //    FormsService.SignIn(model.UserName, model.RememberMe);
                //    if (!String.IsNullOrEmpty(returnUrl))
                //    {
                //        return Redirect(returnUrl);
                //    }
                //    else
                //    {
                //        return RedirectToAction("Index", "Home");
                //    }
                //}
                //else
                //{
                //    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                //}
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #29
0
        public JsonResult UserLogOn_Pad(FormCollection collection)
        {
            Language lang;
            var      service = new SysUserService();
            SysUser  user    = service.Login(collection["UserName"], collection["Password"]);

            if (user == null || string.Compare(user.Pwd, collection["Password"], false) != 0)
            {
                return(Json(new { success = false, msg = "<=PwdorNameError>" }));
            }
            else
            {
                DateTime dt = DateTime.Today;
                if (!(user.ValidDateFrom <= dt && user.ValidDateTo >= dt) || !user.Active)
                {
                    return(Json(new { success = false, msg = "<=UserExpireError>" }));
                }

                //密码过期修改
                if (!user.PasswordDate.HasValue)
                {
                    string errorMsg = string.Empty;
                    user.PasswordDate = DateTime.Now.Date;
                    bool success = service.Save(user, out errorMsg);
                    if (!success)
                    {
                        return(Json(new { success = false, msg = errorMsg }));
                    }
                }
                else
                {
                    if (user.PasswordDate.Value.AddDays(30).Date <= DateTime.Now.Date)
                    {
                        lang = (Language)int.Parse(collection["Lang"]);
                        Response.Cookies["Lang"].Value   = lang == Language.English ? "English" : "SimplifiedChinese";
                        Response.Cookies["Lang"].Expires = DateTime.Now.AddDays(365);
                        return(Json(new { success = false, msg = "expired" }));
                    }
                }

                FormsService.SignIn(collection["UserName"], false);
                lang = (Language)int.Parse(collection["Lang"]);
                Response.Cookies["Lang"].Value   = lang == Language.English ? "English" : "SimplifiedChinese";
                Response.Cookies["Lang"].Expires = DateTime.Now.AddDays(365);
                string s = "FrogDashboard.Service.Services.MasterData.SysManagement.SysFunctionService";
                ISysFunction <SysFunction> service_ = (ISysFunction <SysFunction>)Assembly.Load("FrogDashboard.Service").CreateInstance(s);
                var userRoleId = user.RoleId;
                if (service_.GetUserFunction(userRoleId).Where(c => c.ControllerName == "OrderManagement" && c.ActionName == "TmsForPad").Count() > 0)
                {
                    return(Json(new { success = true, msg = "<LoginSuccess>", URL = "Pad" }));
                }
                else
                {
                    return(Json(new { success = true, msg = "<LoginSuccess>", URL = "Index" }));
                }
            }
        }
コード例 #30
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    StreamReader objLector;
                    string       HTML = "";

                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);

                    // Send welcome e-mail using local host.
                    SmtpClient smtpClient = new SmtpClient();
                    smtpClient.UseDefaultCredentials = true;

                    objLector = System.IO.File.OpenText(Server.MapPath("~/Content/mail/Welcome.html"));
                    HTML      = objLector.ReadToEnd();
                    objLector.Close();

                    HTML = HTML.Replace("@user", model.UserName);

                    string      to      = model.Email;
                    string      from    = "*****@*****.**";
                    MailMessage message = new MailMessage(from, to);
                    message.Subject    = "Welcome to AriasWall";
                    message.Body       = HTML;
                    message.IsBodyHtml = true;
                    //SMTP config.
                    smtpClient.Host = "localhost";
                    smtpClient.Port = 25;

                    try
                    {
                        smtpClient.Send(message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
                                          ex.ToString());

                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }