Ejemplo n.º 1
0
 private async Task SaveUserLoginedAsync(User user, UserLogined userlogined, string curentUserId)
 {
     _context.Entry(user).State = EntityState.Modified;
     user.LastLogin             = DateTime.UtcNow;
     user.UserLogins            = new List <UserLogin>()
     {
         new UserLogin {
             AccessToken    = userlogined.AccessToken,
             ExpiresIn      = userlogined.ExpiresIn.Value.DateTime,
             IsLoggedIn     = userlogined.IsLoggedIn,
             TokenType      = userlogined.TokenType,
             UserId         = user.Id,
             NameIdentifier = curentUserId
         }
     };
     try
     {
         _logger.LogInformation("Save user logined");
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException ex)
     {
         _logger.LogError(ResponseMessageEnum.UpdateDb.GetDescription(), ex);
         throw new ApiException(ResponseMessageEnum.UpdateDb.GetDescription());
     }
 }
        // GET: Shiift
        public ActionResult Index()
        {
            UserLogined u = (UserLogined)Session["user"];

            if (u != null)
            {
                if (u.Logined == true && u.NumOfActions != 0)
                {
                    ubl.UpdateActions(u);
                    Session["user"] = u;
                    var shifts = shiftsBL.GetShiftsData();
                    ViewBag.shifts = shifts;
                    return(View("Shifts"));
                }
                else
                {
                    TempData["Message"] = "You Have no action left for today, pls come back tomorrow";
                    return(RedirectToAction("Logout", "Login"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Index"));
            }
        }
Ejemplo n.º 3
0
        // GET: Employee
        public ActionResult Index()
        {
            UserLogined u = (UserLogined)Session["user"];

            if (u != null)
            {
                if (u.Logined == true && u.NumOfActions != 0)
                {
                    uBL.UpdateActions(u);
                    Session["user"] = u;
                    var departments = depBL.GetAllDepartments();
                    var employees   = empBL.GetAllEmployeeData();
                    ViewBag.employees   = employees;
                    ViewBag.departments = departments;
                    return(View("Employees"));
                }
                else
                {
                    TempData["Message"] = "You Have no action left for today, pls come back tomorrow";
                    return(RedirectToAction("Logout", "Login"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Index"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Logout()
        {
            UserLogined user = (UserLogined)Session["user"];

            user.Logined        = false;
            Session["user"]     = user;
            Session["username"] = null;
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        private UserLogined CreateToken(User user, string userIdentifierId)
        {
            List <Claim> claims = new List <Claim>
            {
                new Claim(UserSignedClaimTypes.UserIdentifierId, userIdentifierId),
                new Claim(UserSignedClaimTypes.CurrentUserId, user.Id.ToString()),
                new Claim(UserSignedClaimTypes.UserName, user.UserName),
                new Claim(ClaimTypes.Email, user.Email)
            };

            if (!string.IsNullOrEmpty(user.StoreId))
            {
                claims.Add(new Claim(UserSignedClaimTypes.StoreIdentifierId, user.StoreId));
            }

            var userRole = user.UserToRoles.Select(x => x.Role).ToList();

            foreach (var role in userRole)
            {
                claims.Add(new Claim(ClaimTypes.Role, role.RoleName));
                var lstPermission = GetPermissionAsync(role).Result;
                foreach (var item in lstPermission)
                {
                    claims.Add(new Claim(PermissionClaimTypes.Permission, item.PermissionName));
                }
            }

            var subjects = new ClaimsIdentity(claims);

            SymmetricSecurityKey key = new SymmetricSecurityKey(Encoding.UTF8
                                                                .GetBytes(_configuration.GetSection("AppSettings:Token").Value));

            SigningCredentials creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);
            var timeExpires          = Convert.ToDouble(_configuration.GetSection("AppSettings:Expires").Value);
            SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = subjects,
                Expires            = DateTime.Now.AddHours(timeExpires),
                SigningCredentials = creds,
                Audience           = _configuration.GetSection("AppSettings:Audience").Value,
                Issuer             = _configuration.GetSection("AppSettings:Issuer").Value,
            };
            JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
            SecurityToken           token        = tokenHandler.CreateToken(tokenDescriptor);

            var userLogined = new UserLogined
            {
                AccessToken = tokenHandler.WriteToken(token),
                ExpiresIn   = token.ValidTo,
                IsLoggedIn  = true,
                TokenType   = JwtBearerDefaults.AuthenticationScheme
            };

            _logger.LogInformation("generate token");
            return(userLogined);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> LoginAndRegisterCustomerV2([FromForm] CustomerLoginDTO model)
        {
            var userLogined = new UserLogined();

            if (ModelState.IsValid)
            {
                userLogined = await _authRepository.SignInAndSignUpCustomerAsync(model);
            }
            return(Ok(userLogined));
        }
Ejemplo n.º 7
0
        public ActionResult CheckLogin(string usrname, string pswrd)
        {
            if (Session["user"] != null)
            {
                UserLogined user = (UserLogined)Session["user"];

                var datetime = DateTime.Now;
                var date     = datetime.Date;

                var userlogindatetime = user.LoginDate;
                var userlogindate     = userlogindatetime.Date;
                if (date != userlogindate)
                {
                    user.LoginDate = DateTime.Now;
                    var userBL = usersBL.AuthorizeUser(usrname, pswrd);
                    user.NumOfActions = userBL.NumOfActions;
                    Session["user"]   = user;
                }

                if (user.Logined == true && user.NumOfActions != 0)
                {
                    return(View("HomePage"));
                }
                else
                {
                    TempData["Message"] = "You Have no action left for today, pls come back tomorrow";
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                var userBL = usersBL.AuthorizeUser(usrname, pswrd);
                if (userBL != null)
                {
                    UserLogined user = new UserLogined();
                    user.FullName       = userBL.FullName;
                    user.UserName       = userBL.UserName;
                    user.Logined        = true;
                    user.LoginDate      = DateTime.Now;
                    user.NumOfActions   = userBL.NumOfActions;
                    Session["user"]     = user;
                    Session["username"] = user.FullName;
                    return(RedirectToAction("HomePage"));
                }
                else
                {
                    TempData["Message"] = "You Are not authorized!";
                    return(RedirectToAction("Index"));
                }
            }
        }
Ejemplo n.º 8
0
        public bool Authenticate(string loginid, string password, string ip)
        {
            var user = userDao.Find(loginid);
            if (user == null)
                return false;

            if (user.Password != password)
                return false;

            var userLogined = new UserLogined(loginid, ip);
            eventBus.Publish(userLogined);

            return true;
        }
Ejemplo n.º 9
0
        private void LoginButton_OnClick(object sender, RoutedEventArgs e)
        {
            var projectName = ProjectNameTextBox.Text ?? string.Empty;
            var account     = AccountTextBox.Text ?? string.Empty;
            var password    = PasswordTextBox.Password ?? string.Empty;

            UserSettingConfigHelper.SetUserSetting(new UserSetting()
            {
                ProjectName = projectName,
                Account     = account,
                Password    = password
            });
            CustomUtils.ProjectName = projectName;
            CustomUtils.Account     = account;
            CustomUtils.Password    = password;
            UserLogined?.Invoke(this, EventArgs.Empty);
            this.Close();
        }
Ejemplo n.º 10
0
Archivo: Program.cs Proyecto: ted9/cqrs
        static void Main(string[] args)
        {
            Configuration.Create(() => new TinyContainer())
            .LoadAssemblies()
            .Done();



            var userRegister = new RegisteringUser {
                UserName = "******",
                Password = "******",
                LoginId  = "guest",
                Email    = "*****@*****.**"
            };


            ObjectContainer.Instance.Resolve <ICommandBus>().Send(userRegister);


            System.Threading.Thread.Sleep(2000);


            var queryService = ObjectContainer.Instance.Resolve <IUserDao>();

            var count = queryService.GetAllUsers().Count();

            Console.WriteLine("user number: " + count);

            var authenticationService = ObjectContainer.Instance.Resolve <IAuthenticationService>();

            if (!authenticationService.Authenticate("guest", "guest"))
            {
                Console.WriteLine("Incorrect username or password");
            }
            else
            {
                Console.WriteLine("Login ok");

                var userLogined = new UserLogined("127.0.0.1");
                ObjectContainer.Instance.Resolve <IEventBus>().Publish(userLogined);
            }

            Console.ReadKey();
        }
Ejemplo n.º 11
0
 public ActionResult HomePage()
 {
     if (Session["user"] != null)
     {
         UserLogined user = (UserLogined)Session["user"];
         if (user.Logined == true && user.NumOfActions != 0)
         {
             return(View("HomePage"));
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }
Ejemplo n.º 12
0
        public async Task <UserLogined> Login(LoginModel loginF)
        {
            try
            {
                var json = JsonConvert.SerializeObject(loginF);
                // use MediaTypeNames.Application.Json in Core 3.0+ and Standard 2.1+
                StringContent loginHttpContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
                var           login            = await _client.PostAsync(ROOT_URL + "/api/account/login", loginHttpContent);

                login.EnsureSuccessStatusCode();
                string categoryContentResponseBody = await login.Content.ReadAsStringAsync();

                UserLogined user = JsonConvert.DeserializeObject <UserLogined>(categoryContentResponseBody);
                return(user);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ERROR In Service: " + ex.Message);
                return(null);
            }
        }
Ejemplo n.º 13
0
 // GET: Login
 public ActionResult Index()
 {
     if (Session["user"] != null)
     {
         UserLogined user = (UserLogined)Session["user"];
         if (user.Logined == true && user.NumOfActions != 0)
         {
             return(RedirectToAction("HomePage"));
         }
         else
         {
             ViewBag.message = TempData["Message"];
             return(View("Login"));
         }
     }
     else
     {
         ViewBag.message = TempData["Message"];
         return(View("Login"));
     }
 }
Ejemplo n.º 14
0
 public async Task SaveToUserLoginAsync(User user, UserLogined userlogined, string currentUserId)
 {
     await SaveUserLoginedAsync(user, userlogined, currentUserId);
 }
Ejemplo n.º 15
0
 public void Handle(UserLogined @event)
 {
     Console.ResetColor();
     Console.WriteLine("User has been logged in");
 }