public ActionResult ClaimUpdate(Guid id)
        {
            Claim claim = null;

            using (BAuthDBContext dc = new BAuthDBContext())
            {
                claim = dc.Claims.Where(c => c.ClaimId == id).SingleOrDefault();

                var password  = Request.Form["password"];
                var newUserBD = new User()
                {
                    UserId     = claim.Email,
                    FirstName  = claim.FirstName,
                    LastName   = claim.LastName,
                    Email      = claim.Email,
                    password   = GetHash(password),
                    PictureUrl = "",
                    CreateDate = DateTime.Now,
                    Role       = "user"
                };

                dc.Users.Add(newUserBD);
                claim.UserId = newUserBD.UserId;
                dc.SaveChanges();
            }

            return(Redirect($"/обезщетение-списък/{claim.ClaimId}"));
        }
Esempio n. 2
0
        public ActionResult Login(string Email, string Password, string ReturnUrl)
        {
            string hashPassword = GetHash(Password);

            User user = null;

            using (BAuthDBContext dc = new BAuthDBContext())
            {
                user = dc.Users.Where(u => u.Email == Email && u.password == hashPassword).SingleOrDefault();
            }

            if (user == null)
            {
                ViewBag.error = "Грешно потребителско име или парола";
                return(View("Login"));
            }



            Session["user"] = user;

            FormsAuthenticationTicket authTicket =
                new FormsAuthenticationTicket(1, user.UserId, DateTime.Now, DateTime.Now.AddMinutes(200), true, user.Role, "/");
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                                               FormsAuthentication.Encrypt(authTicket));

            Response.Cookies.Add(cookie);
            return(Redirect(ReturnUrl));
        }
Esempio n. 3
0
        public static VMUser SyncUserToDatabase(VMUser user)
        {
            user.PictureUrl = user.PictureUrl ?? "";
            user.FirstName  = user.FirstName ?? "";
            user.LastName   = user.LastName ?? "";
            user.Email      = user.Email ?? "";
            user.Role       = user.Role ?? "";

            using (BAuthDBContext context = new BAuthDBContext())
            {
                var userDB = context.Users.Where(u => u.UserId == user.UserId).SingleOrDefault();
                if (userDB != null)
                {
                    user.Role = userDB.Role;
                    return(user);
                }
                user.Role = "";
                var newUserBD = new User()
                {
                    UserId     = user.UserId,
                    FirstName  = user.FirstName,
                    LastName   = user.LastName,
                    Email      = user.Email,
                    PictureUrl = user.PictureUrl,
                    CreateDate = DateTime.Now,
                    Role       = user.Role
                };

                context.Users.Add(newUserBD);
                context.SaveChanges();
                return(user);
            }
        }
Esempio n. 4
0
        public static VMUser GetUserById(string userID)
        {
            VMUser user = null;

            using (BAuthDBContext context = new BAuthDBContext())
            {
                var userDB = context.Users.Where(u => u.UserId == userID).SingleOrDefault();
                if (userDB != null)
                {
                    user = new VMUser()
                    {
                        UserId     = userDB.UserId,
                        FirstName  = userDB.FirstName,
                        LastName   = userDB.LastName,
                        Email      = userDB.Email,
                        PictureUrl = userDB.PictureUrl,
                        Role       = userDB.Role
                    };
                }
            }
            return(user);
        }