Ejemplo n.º 1
0
 private void ValiDateUser(FormCollection frmCol, ref bool createUser)
 {
     if (string.IsNullOrEmpty(frmCol["RegisterModel.UserName"]))
     {
         ModelState.AddModelError("RegisterModel.UserName", "Kullanıcı isminizi giriniz");
         ModelState.AddModelError("", "İsminizi giriniz");
         createUser = false;
     }
     if (string.IsNullOrEmpty(frmCol["RegisterModel.Email"]) || !Regex.IsMatch(frmCol["RegisterModel.Email"], @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
     {
         ModelState.AddModelError("RegisterModel.Email", "Email giriniz");
         createUser = false;
     }
     if (string.IsNullOrEmpty(frmCol["RegisterModel.Password"]))
     {
         ModelState.AddModelError("RegisterModel.Password", "Şifrenizi giriniz");
         createUser = false;
     }
     if (_repoUser.IsRecordUser(frmCol["RegisterModel.Email"]))
     {
         ModelState.AddModelError("RegisterModel.Email", "Email başka bir kullanıcıya ait");
         createUser = false;
     }
 }
Ejemplo n.º 2
0
        public ActionResult Register(RegisterModel model, bool captchaValid, string returnUrl)
        {
            if (ModelState.IsValid && captchaValid)
            {
                // Attempt to register the user
                RepositoryUser repoUser = new RepositoryUser(Server.MapPath("~/App_Data/FrmBlog.db"), DbType.SqLite);
                if (repoUser.IsRecordUser(model.Email))
                {
                    ModelState.AddModelError("Email", "Email başka bir kullanıcıya ait");
                    return(View(model));
                }
                User user = new Models.User();
                user.Email       = model.Email;
                user.RoleId      = Role.Member.RoleId;
                user.Name        = model.UserName;
                user.Password    = model.Password;
                user.PicturePath = new FrmBlog.Avatar.Avatar().GetRandomAvatar();
                user.DisplayName = model.UserName;
                repoUser.Insert(user);
                IFormsAuthentication auth = new FormsAuthenticationWrapper();
                auth.SetAuthCookie(user.Email, true);
                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                    !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            if (!captchaValid)
            {
                ModelState.AddModelError("", "Doğrulama kodu yanlış");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult LogOnPostAssertion(string openid_openidAuthData)
        {
            IAuthenticationResponse response;

            if (!string.IsNullOrEmpty(openid_openidAuthData))
            {
                var auth    = new Uri(openid_openidAuthData);
                var headers = new WebHeaderCollection();
                foreach (string header in Request.Headers)
                {
                    headers[header] = Request.Headers[header];
                }

                // Always say it's a GET since the payload is all in the URL, even the large ones.
                HttpRequestInfo clientResponseInfo = new HttpRequestInfo("GET", auth, auth.PathAndQuery, headers, null);
                response = RelyingParty.GetResponse(clientResponseInfo);
            }
            else
            {
                response = RelyingParty.GetResponse();
            }
            if (response != null)
            {
                switch (response.Status)
                {
                case AuthenticationStatus.Authenticated:
                    string alias = response.FriendlyIdentifierForDisplay;
                    var    sreg  = response.GetExtension <ClaimsResponse>();
                    if (sreg != null && sreg.MailAddress != null)
                    {
                        RepositoryUser userRepo = new RepositoryUser("", DbType.SqLite);
                        if (!userRepo.IsRecordUser(sreg.MailAddress.Address.Trim()))
                        {
                            FrmBlog.Models.User user = new FrmBlog.Models.User();
                            user.DisplayName = sreg.MailAddress.DisplayName;
                            user.Email       = sreg.MailAddress.Address;
                            user.RecordDate  = DateTime.Now;
                            user.RoleId      = FrmBlog.Models.Role.Member.RoleId;
                            user.Name        = sreg.MailAddress.User;
                            user.PicturePath = new FrmBlog.Avatar.Avatar().GetRandomAvatar();
                            userRepo.Insert(user);
                        }
                        else
                        {
                            var user = userRepo.GetUserByEmail(sreg.MailAddress.Address);
                        }
                        //FormsAuthenticationTicket authTicket = new
                        //FormsAuthenticationTicket(1, //version
                        //response.ClaimedIdentifier, // user name
                        //DateTime.Now,             //creation
                        //DateTime.Now.AddMonths(12), //Expiration
                        //true, //Persistent
                        //sreg.MailAddress.Address);

                        //  string encTicket = FormsAuthentication.Encrypt(authTicket);

                        //  this.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                        //  alias = sreg.MailAddress.User;
                        FormsAuthentication.SetAuthCookie(sreg.MailAddress.Address, true);
                    }
                    //if (sreg != null && !string.IsNullOrEmpty(sreg.FullName))
                    //{
                    //    alias = sreg.FullName;
                    //}

                    //FormsAuthenticationTicket authTicket = new
                    //    FormsAuthenticationTicket(1, //version
                    //    response.ClaimedIdentifier, // user name
                    //    DateTime.Now,             //creation
                    //    DateTime.Now.AddDays(365), //Expiration
                    //    false, //Persistent
                    //    alias);

                    //string encTicket = FormsAuthentication.Encrypt(authTicket);

                    //this.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));


                    string returnUrl = Request.Form["returnUrl"];
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                case AuthenticationStatus.Canceled:
                    ModelState.AddModelError("OpenID", "It looks like you canceled login at your OpenID Provider.");
                    break;

                case AuthenticationStatus.Failed:
                    ModelState.AddModelError("OpenID", response.Exception.Message);
                    break;
                }
            }

            // If we're to this point, login didn't complete successfully.
            // Show the LogOn view again to show the user any errors and
            // give another chance to complete login.
            return(View("LogOn"));
        }