コード例 #1
0
        public LoginResponse GetUserForLogin(string email, string password)
        {
            LoginResponse loginResponse = new LoginResponse();

            using (MyDb db = new MyDb())
            {
                try
                {
                    loginResponse.User = db.Users.FirstOrDefault(x => x.Email == email && x.Password == password && x.isActive == true);
                    if (loginResponse.User == null)
                    {
                        loginResponse.SetError(Common.SystemConstant.SystemConstants.ERRORS.NOTFOUND);
                    }
                    else
                    {
                        Token token = new Token();
                        token.Value         = RandomSfr.Generate(50);
                        token.ExpireDate    = DateTime.Now.AddDays(1);
                        loginResponse.Token = token;
                        loginResponse.SetError(Common.SystemConstant.SystemConstants.ERRORS.SUCCESSFUL);
                    }
                }
                catch (Exception)
                {
                    loginResponse.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR);
                }
            }
            return(loginResponse);
        }
コード例 #2
0
        public ActionResult SignUpComplete(User user)
        {
            user.ValidationKey = RandomSfr.Generate(30);
            user.Password      = Security.sha512encrypt(user.Password).Substring(0, 40);
            user.Address       = user.Address;
            user.Phone         = user.Phone;
            user.isActive      = false;
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:5006/");
            HttpResponseMessage result = client.PostAsJsonAsync("api/Login/SignUp", user).Result;

            if (result.StatusCode == HttpStatusCode.OK)
            {
                string resultString = result.Content.ReadAsStringAsync().Result;
                if (resultString != "{\"Code\":0}")
                {
                    SignUpRespone login = Newtonsoft.Json.JsonConvert.DeserializeObject <SignUpRespone>(resultString);
                    if (login.Code == 1)
                    {
                        TempData["Success"] = "Kayıt İşlemi Başarılı Mail Kutunuzu Kontrol Edin!";
                        return(RedirectToAction("Index", "Login"));
                    }
                }
            }
            TempData["Error"] = "Bazı  şeyler ters gitti tekrar deneyin!!";
            return(RedirectToAction("SignUp", "Login"));
        }
コード例 #3
0
        public ActionResult Login(Data.User user)
        {
            string returnUrl = Request["returnUrl"];

            LoginResponse response = new LoginResponse((int)CommonContant.LANGUAGEID.TR);

            try
            {
                using (Data.SimpleData db = new Data.SimpleData())
                {
                    string password = Security.sha512encrypt(user.Password).Substring(0, 70);
                    var    User     = db.Users.FirstOrDefault(t => t.Email == user.Email && t.Password == password);


                    if (User == null)
                    {
                        response.SetErrror(CommonContant.ERROR_CODE.NONACTIVEUSER);
                        return(View(response));
                    }

                    if (User.ActiveStatus != (int)CommonContant.ActiveStatus.activeuser)
                    {
                        response.SetErrror(CommonContant.ERROR_CODE.NONACTIVEUSER);
                        return(View(response));
                    }


                    Data.Token token = new Data.Token
                    {
                        CreateDate = DateTime.Now,
                        ExpireDate = DateTime.Now.AddHours(6),
                        TokenKey   = Security.sha512encrypt(RandomSfr.Generate(20)),
                    };
                    User.Tokens.Add(token);
                    db.SaveChanges();

                    HttpCookie c*k = new HttpCookie("userauth", token.TokenKey);
                    c*k.Expires = DateTime.Now.AddHours(6);
                    Response.Cookies.Add(c*k);

                    Session["User"] = User;

                    if (string.IsNullOrEmpty(returnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(Redirect(returnUrl));
                    }
                }
            }
            catch (Exception ex)
            {
                response.SetErrror(CommonContant.ERROR_CODE.SYSTEM_ERROR);
            }

            return(View());
        }
コード例 #4
0
        public ActionResult Login(admin.Models.LoginViewModel userdata)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }


            oylmzEntities datas = new oylmzEntities();


            User loginUser = datas.Users.Where(t => t.userName == userdata.userName && t.password == userdata.password).FirstOrDefault();



            if (loginUser == null)
            {
                ViewBag.hata = "Kullanıcı adı veya şifre hatalı";
                return(View());
            }


            Token token = new Token();


            do
            {
                token.enddate   = DateTime.Now.AddHours(2);
                token.tokentext = RandomSfr.Generate(10);
            } while (datas.Tokens.Count(t => t.tokentext == token.tokentext) > 0);


            token.userId = loginUser.Id;

            datas.Tokens.Add(token);
            datas.SaveChanges();


            HttpCookie c*k = new HttpCookie("tk");

            c*k.Value   = token.tokentext;
            c*k.Expires = DateTime.Now.AddHours(2);


            Response.Cookies.Add(c*k);



            return(RedirectToAction("Index", "Home"));
        }
コード例 #5
0
        public ActionResult Login(ofora.Models.LoginViewModel userdata)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("login", "Home"));
            }



            ojelerForaEntities1 datas = new ojelerForaEntities1();

            User loginUser = datas.Users.Where(t => t.userName == userdata.userName && t.password == userdata.password && t.ustatus == 3 && t.onayDurumu == 1).FirstOrDefault();



            if (loginUser == null)
            {
                return(RedirectToAction("login", "Home", new { id = 99 }));
            }


            Token token = new Token();


            do
            {
                token.endate    = DateTime.Now.AddHours(2);
                token.tokentext = RandomSfr.Generate(10);
            } while (datas.Tokens.Count(t => t.tokentext == token.tokentext) > 0);


            token.userId = loginUser.Id;

            datas.Tokens.Add(token);
            datas.SaveChanges();


            HttpCookie c*k = new HttpCookie("tk");

            c*k.Value   = token.tokentext;
            c*k.Expires = DateTime.Now.AddHours(2);


            Response.Cookies.Add(c*k);

            return(RedirectToAction("Index", "Home"));
        }
コード例 #6
0
        // GET: Activation
        public ActionResult Activate(string email, string validationkey)
        {
            Responses.BaseResponse response = new Responses.BaseResponse((int)CommonContant.LANGUAGEID.TR);

            try
            {
                using (Data.SimpleData db = new Data.SimpleData())
                {
                    var    User    = db.Users.FirstOrDefault(t => t.Email == email);
                    string userkey = null;

                    if (User != null)
                    {
                        userkey = Security.sha512encrypt(User.ValidationKey);
                    }

                    if (userkey == validationkey)
                    {
                        User.ActiveStatus    = (int)CommonContant.ActiveStatus.activeuser;
                        User.ValidationKey   = RandomSfr.Generate(10);
                        db.Entry(User).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        response.SetErrror(CommonContant.ERROR_CODE.SECURTYERROR);
                        return(View(response));
                    }
                }
            }
            catch (Exception ex)
            {
                response.SetErrror(CommonContant.ERROR_CODE.SYSTEM_ERROR);
                return(View(response));
            }


            return(View(response));
        }
コード例 #7
0
        public ActionResult SignUpUser(User user)
        {
            if (ModelState.IsValid)
            {
                user.AccountActiveDate = DateTime.Now;
                user.AccountCreateDate = DateTime.Now;
                user.Password          = Security.sha512encrypt(user.Password).Substring(0, 70);
                user.Image             = "";
                user.isActive          = false;
                user.isBlocked         = false;
                user.ValidationKey     = RandomSfr.Generate(10);
                user.WrongCount        = 0;
                user.RoleID            = 1;

                HttpResponseMessage result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress,
                                                                                                        "api/Account/SignUp", user);

                //HttpClient client = new HttpClient();
                //client.BaseAddress = new Uri("http://localhost:2765/");
                //HttpResponseMessage result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress,
                //	"api/Account/SignUp", user);

                if (result.StatusCode == HttpStatusCode.OK)
                {
                    string resultString = result.Content.ReadAsStringAsync().Result;
                    if (resultString.Contains("true"))
                    {
                        return(RedirectToAction("Login", "Account"));
                    }
                    else
                    {
                        return(RedirectToAction("SignUp", "Account", user));
                    }
                }
            }
            return(RedirectToAction("SignUp", "Account", user));
        }
コード例 #8
0
        public async Task <ActionResult> Register(Data.User user)
        {
            user.EmailConfirm  = false;
            user.ActiveStatus  = (int)CommonContant.ActiveStatus.pasif;
            user.Password      = SimpleLogin.Common.Security.sha512encrypt(user.Password).Substring(0, 70);
            user.ValidationKey = RandomSfr.Generate(10);
            Data.SimpleData db = new Data.SimpleData();
            db.Entry(user).State = System.Data.Entity.EntityState.Added;

            try
            {
                int result = await db.SaveChangesAsync();

                //db ye kayıt edildi
                if (result == 1)
                {
                    string link = "http://localhost:58522/Activation/Activate/" + user.Email + "/" + Security.sha512encrypt(user.ValidationKey);

                    string emailFromTemplate = HelperFunction.RenderViewToString(this.ControllerContext, "~/Views/MailTemplates/UserActivation.cshtml", link);


                    //todo:  metod async yapılacak
                    Common.MailOperations.sendMailFORapp("WissenApp Kayıt", emailFromTemplate, user.Email);


                    return(RedirectToAction("ActivationInfo"));
                }
            }
            catch (Exception ex)
            {
                throw;
            }



            return(View());
        }
コード例 #9
0
        public bool SocialUserOperation(int socialType, string socialID, string email, string username, string firstname, string lastname, string methodName)
        {
            //bu kullanıcı daha once kayıt olmuşmu
            SocialUser socialUser = _socialUserDal.Get(t => t.SOCIALID == socialID && t.SocialType == socialType);

            //daha önce kayıt olmamış ise
            if (socialUser == null)
            {
                //bir kullanıcı tanımlama
                User user = new User
                {
                    ActiveStatus      = (int)SystemConstannts.Situation.SOCİALUSER,
                    Name              = firstname,
                    Surname           = lastname,
                    isActive          = true,
                    Password          = Common.RandomSfr.Generate(8),
                    AccountCreateDate = DateTime.Now,
                    AccountActiveDate = DateTime.Now,
                    Address           = "hdfdjfdk jdhdfjd",
                    PhoneNumber       = "12344555"
                };
                user.Tokens = new List <Token>();

                //o kullanıcıyı socialUser olarak atama
                socialUser = new SocialUser
                {
                    CreateDate = DateTime.Now,
                    SocialType = socialType,
                    SOCIALID   = socialID,
                    UserID     = user.ID
                };

                //o kullanıcıya token oluşturma
                Token token = new Token
                {
                    StartDate  = DateTime.Now,
                    ExpireDate = DateTime.Now.AddHours(6),
                    TokenValue = Security.sha512encrypt(RandomSfr.Generate(20)),
                };
                //user.Tokens.Add(token);
                HttpCookie c*k = new HttpCookie("userAuth", token.TokenValue);
                c*k.Expires = DateTime.Now.AddHours(6);
                HttpContext.Current.Response.Cookies.Add(c*k);
                HttpContext.Current.Session["User"] = user;

                //oluşturulan user ve socialuser ı database e kayıt etme
                //  int eklenenUserID = _userDal.UserAddReturnUserId(user);
                //var userr = _userDal.Get(t => t.Name == user.Name && t.Surname == user.Surname && t.Password == user.Password);
                //  socialUser.UserID = eklenenUserID;

                if (String.IsNullOrEmpty(methodName))
                {
                    //ValidationTool.Validate(new UserValidator(), user);
                    UserValidator    validator = new UserValidator();
                    ValidationResult result    = validator.Validate(user);

                    // TANSU BURAYA DUSMESI LAZIM CODUN
                    // Kullaniciyi eklemeden buraya breakpoint koyar misin bakalim buraya dusucek mi
                    // Tam _socialUserDal.Add(socialUser); un oraya koy ekleme yapmasin ama oraya dustugunu gorelim
                    //oluşturulan user ve socialuser ı database e kayıt etme
                    user.Tokens.Add(token);
                    int eklenenUserID = _userDal.UserAddReturnUserId(user);
                    //var userr = _userDal.Get(t => t.Name == user.Name && t.Surname == user.Surname && t.Password == user.Password);
                    socialUser.UserID = eklenenUserID;



                    _socialUserDal.Add(socialUser);
                }
                else
                {
                    ValidationTool.Validate(new UserValidatorNotNull(), user);
                    UserValidatorNotNull validator = new UserValidatorNotNull();
                    ValidationResult     result    = validator.Validate(user);
                }
                // _socialUserDal.Add(socialUser); buradaydi If icerisine aldim


                try
                {
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
            else
            {
                int               id  = socialUser.UserID;
                Token             tkn = _tokenDal.Get(t => t.User_ID == id);
                List <SocialUser> socialUserEager;
                if (tkn.ExpireDate < DateTime.Now)
                {
                    //bu kullanıcı daha once kayıt olmuş ise ve token expiredate zamanı geçmiş ise Token ekle
                    Token token = new Token
                    {
                        StartDate  = DateTime.Now,
                        ExpireDate = DateTime.Now.AddHours(6),
                        TokenValue = Security.sha512encrypt(RandomSfr.Generate(20)),
                    };
                    //socialUser.User.Tokens.Add(token); işlemi için oluşturulan EagerLoadingUser() mettodundan socialuser alma
                    socialUserEager = EagerLoadingUser();
                    foreach (var item in socialUserEager)
                    {
                        item.User.Tokens.Add(token);
                    }

                    HttpCookie c*k = new HttpCookie("userAuth", token.TokenValue);
                    c*k.Expires = DateTime.Now.AddHours(6);
                    HttpContext.Current.Response.Cookies.Add(c*k);
                }
                socialUserEager = EagerLoadingUser();
                foreach (var item in socialUserEager)
                {
                    HttpContext.Current.Session["User"] = item.User;
                }

                try
                {
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }

            return(false);
        }
コード例 #10
0
        public object Login(User user)
        {
            LoginResponse loginResponse = new LoginResponse();

            try
            {
                user = _userService.CheckUser(user);
                if (user == null)
                {
                    loginResponse.setError(Common.SystemConstants.SystemConstannts.ERROR_CODES.NOTFOUND);
                    loginResponse.Token = null;
                    return(loginResponse);
                }
                else
                {
                    Token token = new Token()
                    {
                        User_ID    = user.ID,
                        IP         = "",
                        OS         = "",
                        ExpireDate = DateTime.Now.AddDays(1),
                        Browser    = "",
                        StartDate  = DateTime.Now,
                        TokenValue = RandomSfr.Generate(60),
                    };

                    #region Burasi Cozuldu- Sorunsuz bir sekilde WebApiConfig te yazdigimiz 3 satir json code ile cozuldu

                    /*User lUser = new User()
                     * {
                     * ID = user.ID,
                     * Name = user.Name,
                     * Surname = user.Surname,
                     * Email = user.Email,
                     * Address = user.Address,
                     * PhoneNumber = user.PhoneNumber,
                     * Image = user.Image,
                     * AccountCreateDate = user.AccountCreateDate,
                     * AccountActiveDate = user.AccountActiveDate,
                     * ValidationKey = user.ValidationKey,
                     * WrongCount = user.WrongCount,
                     * RoleID = user.RoleID,
                     * isActive = user.isActive,
                     * ActiveStatus = user.ActiveStatus,
                     * isBlocked = user.isBlocked,
                     * Password = user.Password,
                     * Tokens = null
                     * };*/
                    #endregion

                    _tokenService.Add(token);
                    loginResponse.Token      = token;
                    loginResponse.Token.User = user;
                    loginResponse.setError(Common.SystemConstants.SystemConstannts.ERROR_CODES.SUCCESS);
                    return(loginResponse);
                }
            }
            catch (Exception ex)
            {
                loginResponse.setError(Common.SystemConstants.SystemConstannts.ERROR_CODES.SYSTEMERROR);
                return(loginResponse);
            }
        }