/// <summary>
        /// Function for check login details
        /// </summary>
        /// <param name="login_VM"></param>
        /// <returns></returns>
        public Login_VM Login(Login_VM login_VM)
        {
            var result = _context.Sec_Users.Where(x => x.Email == login_VM.Email && x.IsDeleted.Value != true && x.Active.Value).FirstOrDefault();

            if (result != null)
            {
                var encryptPwd = Helper.Encrypt(login_VM.Password);
                if (encryptPwd == result.Password)
                {
                    // check client
                    var client = _context.Sec_Client.Where(x => x.Id == result.ClientId && x.IsDeleted != true && x.Status == true).FirstOrDefault();
                    if (client != null)
                    {
                        login_VM.IsAdmin    = result.IsAdmin != null ? result.IsAdmin.Value : false;
                        login_VM.UserId     = result.Id;
                        login_VM.FullName   = result.FullName;
                        login_VM.ProfilePic = result.ProfilePicture != null ? result.ProfilePicture : "";
                        login_VM.ClientId   = result.ClientId;
                        login_VM.IsAllowVoucherApprovalPermission = login_VM.IsAdmin ? true : result.IsAllowVoucherApprovalPermission;
                        login_VM.IsAllowVoucherIssuancePermission = login_VM.IsAdmin ? true : result.IsAllowVoucherIssuancePermission;
                        return(login_VM);
                    }
                }
            }
            return(null);
        }
        public IActionResult Authentication(Login_VM model)
        {
            _logger.LogInformation("Authentication::Start");
            if (ModelState.IsValid)
            {
                _logger.LogInformation("Model::Done");
                var result = _userRepository.Login(model);
                if (result != null)
                {
                    _logger.LogInformation("User::Valid");
                    HttpContext.Session.SetString("fullname", result.FullName);
                    HttpContext.Session.SetInt32("UserId", result.UserId);
                    HttpContext.Session.SetInt32("IsAdmin", result.IsAdmin ? 1 : 0);
                    HttpContext.Session.SetInt32("SelectedConceptId", 0);
                    HttpContext.Session.SetInt32("ClientId", result.ClientId);
                    HttpContext.Session.SetInt32("HasVoucherIssuancePermission", result.IsAllowVoucherIssuancePermission ? 1 : 0);
                    HttpContext.Session.SetInt32("HasAllowVoucherApprovalPermission", result.IsAllowVoucherApprovalPermission ? 1 : 0);
                    string pic        = result.ProfilePic;
                    var    folderName = "/" + _configuration.GetValue <string>("UploadFolder");
                    var    path       = Path.Combine(folderName, pic);
                    HttpContext.Session.SetString("imgpath", path);


                    return(RedirectToActionPermanent("Index", "Dashboard"));
                }
                _logger.LogInformation("User::InValid");
                ModelState.AddModelError("", Message.invalidLogin);
            }
            _logger.LogInformation("Authentication::End");
            return(View("Index", model));
        }
 public LoginPage_Desktop()
 {
     this.InitializeComponent();
     LoginUser   = new Login_VM(new LoginClass());
     MyFrame     = (Frame)DesktopAppSettings.GetItem("myFrameKeyforLoginNavigationtoLoginPage");
     DataContext = LoginUser;
 }
Exemplo n.º 4
0
        public ActionResult index(Login_VM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            return(View());
        }
Exemplo n.º 5
0
        public User GetT(Login_VM _model)
        {
            var result = db.User.Where(x => x.ID == _model.ID && x.Password == _model.Password).FirstOrDefault();

            if (result != null)
            {
                User = result.ID;
                Name = result.Name;
            }
            return(result);
        }
Exemplo n.º 6
0
        public IActionResult Login([FromBody] Login_VM login)
        {
            IActionResult response = Unauthorized();
            var           user     = accountRepository.LoginTaskSync(login.Email, login.Password);

            if (user != null)
            {
                var tokenString = GenerateJSONWebToken(user);
                response = Ok(new { token = tokenString });
            }

            return(response);
        }
Exemplo n.º 7
0
        public Login_VM LoginTaskSync(string email, string password)
        {
            Login_VM result = null;

            string connectStr = "Data Source=DESKTOP-ILI17T6;Initial Catalog=CodingCamp44;User ID=sa;Password=sapassword;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";//ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;

            using (IDbConnection db = new SqlConnection(connectStr))
            {
                string readSp    = "sp_retrieve_login";
                var    parameter = new { Email = email, Password = password };
                result = db.Query <Login_VM>(readSp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            return(result);
        }
        /// <summary>
        /// Function for Super Admin Login
        /// </summary>
        /// <param name="login_VM"></param>
        /// <returns></returns>
        public Login_VM SuperAdminLogin(Login_VM login_VM)
        {
            var result = _context.Sec_SuperUser.Where(x => x.Email == login_VM.Email && x.IsDeleted != true && x.Status).FirstOrDefault();

            if (result != null)
            {
                var encryptPwd = Helper.Encrypt(login_VM.Password);
                if (encryptPwd == result.Password)
                {
                    login_VM.UserId     = result.Id;
                    login_VM.FullName   = result.UserName;
                    login_VM.ProfilePic = "";
                    return(login_VM);
                }
            }
            return(null);
        }
Exemplo n.º 9
0
        private string GenerateJSONWebToken(Login_VM userInfo)
        {
            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]));
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
            var dataPerson  = personRepository.GetDataByEmail(userInfo.Email);

            var claims = new[] {
                new Claim("Email", dataPerson.Email),
                new Claim("FirstName", dataPerson.FirstName),
                new Claim("LastName", dataPerson.LastName)
            };

            var token = new JwtSecurityToken(Configuration["Jwt:Issuer"],
                                             Configuration["Jwt:Issuer"],
                                             claims,
                                             expires: DateTime.Now.AddMinutes(120),
                                             signingCredentials: credentials);

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
        public async Task <IActionResult> Login([FromForm] Login_VM req)
        {
            var response = await _client.PostAsJsonAsync($"/Account/Login", new { Username = req.Username, Password = req.Password });

            var stringRes = await response.Content.ReadAsStringAsync();

            var res = JsonConvert.DeserializeObject <ServiceResponseSingle <LoginRes> >(stringRes);

            if (res != null)
            {
                HttpContext.Session.SetString(SessionAttr.JWT_Token, res.Data.JWT_Token);
                HttpContext.Session.SetString(SessionAttr.Refresh_Token, res.Data.Refresh_Token);

                return(View("Menu"));
            }
            else
            {
                return(View());
            }
        }
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            Login_VM x = new Login_VM();

            var response = x.CheckAuth(LoginUser);

            if (response)
            {
                var dialog = new MessageDialog("Login Complete!");
                await dialog.ShowAsync();

                DesktopAppSettings.AddItem("LoggedUser", LoginUser);
                MyFrame.Navigate(typeof(AccountPage_Desktop));
            }
            else
            {
                var dialog = new MessageDialog("User or password incorrect!! Please try again.");
                await dialog.ShowAsync();
            }
        }
 public IActionResult Authentication(Login_VM model)
 {
     if (ModelState.IsValid)
     {
         var result = _userRepository.SuperAdminLogin(model);
         if (result != null)
         {
             HttpContext.Session.SetString("fullname", result.FullName);
             HttpContext.Session.SetInt32("UserId", result.UserId);
             HttpContext.Session.SetInt32("IsAdmin", 0);
             HttpContext.Session.SetInt32("IsSuperAdmin", 1);
             string pic        = result.ProfilePic;
             var    folderName = "/" + _configuration.GetValue <string>("UploadFolder");
             var    path       = Path.Combine(folderName, pic);
             HttpContext.Session.SetString("imgpath", path);
             return(RedirectToActionPermanent("List", "Client"));
         }
         ModelState.AddModelError("", Message.invalidLogin);
     }
     return(View("Index", model));
 }
Exemplo n.º 13
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string   pwd     = Md5.MD5TwiceEncode("123456");
            Login_VM vmLogin = DataContext as Login_VM;

            if (vmLogin == null)
            {
                return;
            }

            if (vmLogin.IsModelValid())
            {
                WebApiClientHelper.UserName = vmLogin.UserName;
                WebApiClientHelper.Password = vmLogin.Password;
                UserInfo_API_Get userInfo;
                try
                {
                    userInfo = WebApiClientHelper.DoJsonRequest <UserInfo_API_Get>(GlobalData.GetResUri("entrance"), EnuHttpMethod.Get);
                }
                catch (ClientException ex)
                {
                    vmLogin.SetExtraError(ex.Message);
                    return;
                }

                //验证成功,记录用户信息
                GlobalData.CurrentUserName = userInfo.UserName;
                GlobalData.CurrentDispName = userInfo.RealName;
                GlobalData.CurrentRole     = userInfo.Role;

                //转入主窗口
                MainWindow main = new MainWindow();
                Application.Current.MainWindow = main;
                Close();
                main.Show();
            }
        }
Exemplo n.º 14
0
        public ActionResult Index(Login_VM model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "請輸入帳號密碼。");
                return(View(model));
            }

            LoginLogic _user = new LoginLogic();


            if (_user.GetT(model) == null)
            {
                ModelState.AddModelError("", "無效的帳號或密碼。");
                return(View(model));
            }

            var ticket = new System.Web.Security.FormsAuthenticationTicket(
                version: 1,
                name: _user.User.ToString(),                //可以放使用者Id
                issueDate: DateTime.UtcNow,                 //現在UTC時間
                expiration: DateTime.UtcNow.AddMinutes(30), //Cookie有效時間=現在時間往後+30分鐘
                isPersistent: true,                         // 是否要記住我 true or false
                userData: _user.Name,                       //可以放使用者角色名稱

                cookiePath: FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket); //把驗證的表單加密
            var cookie          = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            Response.Cookies.Add(cookie);

            //Session["username"] = _user.Name.ToString();

            return(RedirectToAction("Index", "Workout"));
        }
Exemplo n.º 15
0
 public MainPage_Desktop()
 {
     this.InitializeComponent();
     x = new Login_VM();
 }