Ejemplo n.º 1
0
        public ActionResult <LoggedUserDTO> Authenticate([FromBody] LoginDTO dto)
        {
            var user = this.userService.Authenticate(dto.Username, dto.Password);

            if (user == null)
            {
                return(Unauthorized());
            }

            var responseDto = new LoggedUserDTO()
            {
                Username = user.Username,
                Email    = user.Email,
                Token    = user.Token,
                Id       = user.Id,
                Image    = user.Image
            };

            return(responseDto);
        }
Ejemplo n.º 2
0
        public string isLoginSuccess(LoginDTO login)
        {
            List <DoktorEntities> doktorlar = DoktorlariGetir();

            foreach (DoktorEntities item in doktorlar)
            {
                if (item.KullaniciAdi == login.KullaniciAdi)
                {
                    if (item.Sifre == login.Password)
                    {
                        return(item.DoktorID.ToString());
                    }
                    else
                    {
                        return("Sifre yanlış");
                    }
                }
            }
            return("Kullanıcı adı yanlış");
        }
Ejemplo n.º 3
0
        //DIT IS DE LOG IN.
        public async Task <ActionResult <String> > CreateToken(LoginDTO model) //Hierin staat de mail en password. In de model kan je weer validatie vinden.
        {
            //Gebruiker opzoeken a.d.h.v usermanager.
            var user = await _userManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                //Kijken off password klopt.
                var result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

                if (result.Succeeded)
                {
                    //Als password klopt, wordt token terug opgevraagt en terug gestuurd naar de view.
                    string token = GetToken(user);
                    return(Created("", token)); //returns only the token
                }
            }
            //Als account niet bestaat, Bad Request (Code 400).
            return(BadRequest());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Login(LoginDTO login)
        {
            if (ModelState.IsValid)
            {
                var result = await _userService.Login(login);

                if (result == null)
                {
                    return(NotFound());
                }
                else
                {
                    return(Ok(result));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 5
0
        public ActionResult Connexion(String log_username, String log_password)
        {
            LoginDTO logg = db.Authentifier(log_username, log_password);

            if (logg == null)
            {
                return(HttpNotFound());
            }

            String premierCaractere = logg.name.Substring(0, 1);
            String premierCar       = logg.firstname.Substring(0, 1);

            Session["CarNom"]    = premierCaractere;
            Session["CarPrenom"] = premierCar;
            Session["Nom"]       = logg.name;
            Session["Prenom"]    = logg.firstname;
            Session["ID"]        = logg.id_user;

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 6
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            LoginDTO login = new LoginDTO
            {
                TenDN   = usernameTextBox.Text,
                MatKhau = passwordTextBox.Text.GetSHA1Hash()
            };

            var nv = DbLib.GetOne <NhanVien>("SP_GETBYUSERNAMEANDPASS_PUBLIC_ENCRYPT_NHANVIEN", login.ToSqlParameter());

            if (nv != null)
            {
                MessageBox.Show("Đăng nhập thành công nha !");
                var frmQLSV = new frmQuanLySV(nv, passwordTextBox.Text);
                this.Hide();
                frmQLSV.Show();
                return;
            }
            MessageBox.Show("Tên đăng nhập hoặc mật khẩu không thèm đúng !");
        }
Ejemplo n.º 7
0
        public string isLoginSuccess(LoginDTO login)
        {
            List <HastaEntities> hastalar = GetHastalar();

            foreach (HastaEntities item in hastalar)
            {
                if (item.KullaniciAdi == login.KullaniciAdi)
                {
                    if (item.Sifre == login.Password)
                    {
                        return(item.HastaID.ToString());
                    }
                    else
                    {
                        return("Sifre yanlış");
                    }
                }
            }
            return("E-mail yanlış");
        }
Ejemplo n.º 8
0
        public string isLoginSuccess(LoginDTO login)
        {
            List <EczaciEntities> eczacilar = GetEczacilar();

            foreach (EczaciEntities item in eczacilar)
            {
                if (item.KullaniciAdi == login.KullaniciAdi)
                {
                    if (item.Sifre == login.Password)
                    {
                        return(item.EczaciID.ToString());
                    }
                    else
                    {
                        return("Sifre yanlış");
                    }
                }
            }
            return("Kullanıcı adı yanlış");
        }
        public async Task <IActionResult> Login(LoginDTO login)
        {
            var result = await _signInManager.PasswordSignInAsync(login.UserName, login.Password, false, false);

            if (result.Succeeded)
            {
                var user = await _userManager.FindByNameAsync(login.UserName);

                var identityRole = await _userManager.GetRolesAsync(user);

                var token = CreateToken(user, identityRole.ToList());

                return(Ok(new
                {
                    jwt = new JwtSecurityTokenHandler().WriteToken(token),
                    expiration = token.ValidTo
                }));
            }
            return(BadRequest("Invalid login attempt"));
        }
Ejemplo n.º 10
0
        public string isLoginSuccess(LoginDTO login)
        {
            List <HastaEntity> hastalar = HastalariGetir();

            foreach (HastaEntity item in hastalar)
            {
                if (item.HastaEmail == login.Email)
                {
                    if (item.HastaSifre == login.Sifre)
                    {
                        return(item.HastaID.ToString());
                    }
                    else
                    {
                        return("Şifre yanlış!");
                    }
                }
            }
            return("Email yanlış!");
        }
Ejemplo n.º 11
0
        public string isLoginSuccess(LoginDTO login)
        {
            List <DoktorEntity> doktorlar = DoktorlariGetir();

            foreach (DoktorEntity item in doktorlar)
            {
                if (item.DoktorEmail == login.Email)
                {
                    if (item.DoktorSifre == login.Sifre)
                    {
                        return(item.DoktorID.ToString());
                    }
                    else
                    {
                        return("Şifre yanlış!");
                    }
                }
            }
            return("Email yanlış!");
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Login(LoginDTO loginUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _signInManager.PasswordSignInAsync(loginUser.Email, loginUser.Password, false, true);

            if (result.Succeeded)
            {
                return(Ok(GerarJwt()));
            }
            if (result.IsLockedOut)
            {
                return(BadRequest("Usuário temporariamente bloqueado por tentativas inválidas"));
            }

            return(BadRequest("Usuário ou Senha incorretos"));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Login([FromBody] LoginDTO login)
        {
            try
            {
                var usuario = await _userService.ConsultarUsuario(login);

                if (!string.IsNullOrEmpty(usuario.MensagemRetorno))
                {
                    return(ResponseErrorJson("", usuario.MensagemRetorno));
                }

                var tokenModel = _tokenService.GerarToken(usuario);

                return(ResponseOkJson(tokenModel, "Autenticado com Sucesso!"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Login([FromBody] LoginDTO model)
        {
            Microsoft.AspNetCore.Identity.SignInResult res = await _userService.Login(model);

            User user = await _userService.FindUserByEmail(model.email);

            if (res.Succeeded)
            {
                var token = await _userService.Authenticate(user);

                return(Ok(new { token }));
            }

            if (user == null)
            {
                return(BadRequest("InvalidUserNameOrPassword"));
            }

            return(BadRequest("LoginFailed"));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Login(LoginDTO loginDTO)
        {
            if (loginDTO.Email == null || loginDTO.Password == null)
            {
                return(BadRequest(loginDTO));
            }

            var user = _authService.AuthenticateUser(loginDTO);

            if (user == null)
            {
                return(Unauthorized());
            }
            else
            {
                await _authService.Login(HttpContext, user);

                return(Ok(_mapper.Map <UserDTO>(user)));
            }
        }
Ejemplo n.º 16
0
        public ActionResult Login(LoginDTO uye)
        {
            uye.Parola = PassManager.Base64Encrypt(uye.Parola);//Uye parola şifre çözümü yapıldı.
            var result = _loginService.GetUserInformation(uye.KullaniciAdi, uye.Parola);

            if (result != null)
            {
                //install-package automapper -version:4.1 kurulumu yapılacak.
                AutoMapper.Mapper.DynamicMap(result, _sessionContext);
                Session["SessionContext"] = _sessionContext;
                Session["UyeID"]          = _sessionContext.UyeID;
                Session["KullaniciAdi"]   = _sessionContext.KullaniciAdi;

                return(Json("/DashboardPanel", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 17
0
        public string isLoginSuccess(LoginDTO login)
        {
            List <EczaneEntity> eczaneler = EczaneleriGetir();

            foreach (EczaneEntity item in eczaneler)
            {
                if (item.EczaneEmail == login.Email)
                {
                    if (item.EczaneSifre == login.Sifre)
                    {
                        return(item.EczaneID.ToString());
                    }
                    else
                    {
                        return("Şifre yanlış!");
                    }
                }
            }
            return("Email yanlış!");
        }
        public Kullanici Giris(LoginDTO giris)
        {
            List <Kullanici> kullanicilar = KullaniciDAL.KullaniciGetir();

            foreach (Kullanici item in kullanicilar)
            {
                if (item.Mail == giris.Mail)
                {
                    if (item.Sifre == giris.Sifre)
                    {
                        return(item);
                    }
                    else
                    {
                        throw new Exception("Şifre hatalı");
                    }
                }
            }
            throw new Exception("Mail hatalı");
        }
        public async Task <TokenDTO> SignInAsync(LoginDTO credentials)
        {
            try
            {
                var user = (await _unitOfWork.UserManager.FindByNameAsync(credentials.Login));

                if (user != null && (bool)user.IsActive && (await _unitOfWork.UserManager.CheckPasswordAsync(user, credentials.Password)))
                {
                    var role  = (await _unitOfWork.UserManager.GetRolesAsync(user)).SingleOrDefault();
                    var token = _jwtFactory.GenerateToken(user.Id, user.UserName, role);
                    return(token);
                }
                return(null);
            }
            catch (Exception e)
            {
                _logger.LogError(e, nameof(SignInAsync));
                throw;
            }
        }
Ejemplo n.º 20
0
        public async Task <AuthResult <Token> > Login(LoginDTO loginDto)
        {
            if (loginDto == null || string.IsNullOrEmpty(loginDto.Email) || string.IsNullOrEmpty(loginDto.Password))
            {
                return(AuthResult <Token> .UnvalidatedResult);
            }

            var user = await userManager.FindByEmailAsync(loginDto.Email);

            if (user != null)
            {
                if (await userManager.CheckPasswordAsync(user, loginDto.Password))
                {
                    var token = jwtManager.GenerateToken(user);
                    return(AuthResult <Token> .TokenResult(token));
                }
            }

            return(AuthResult <Token> .UnauthorizedResult);
        }
        public async Task <SignInResult> Login(LoginDTO loginDTO)
        {
            var usr = await _unitOfWork.AppUser.GetFilteredFirstOrDefault(selector : x => x.Status, expression : x => x.UserName == loginDTO.UserName);

            if (usr != null)
            {
                if (usr != Status.Passive)
                {
                    return(await _signInManager.PasswordSignInAsync(loginDTO.UserName.ToUpper(), loginDTO.Password, loginDTO.RememberMe, false));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 22
0
        public IHttpActionResult Login(LoginDTO loginDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool isCredentialValid = (loginDTO.Password == "123456");

            if (isCredentialValid)
            {
                var token = TokenGenerator.GenerateTokenJwt(loginDTO.Username);
                return(Ok(token));
            }

            else
            {
                return(Unauthorized());   // Status code 401
            }
        }
Ejemplo n.º 23
0
        //login işleimde mail ve şifreyle örtüşüyor mu onu kontrol edicez
        public string Login(LoginDTO login)
        {
            List <Hastalar> patients = _hastalarManagement.GetAllPatients();

            foreach (Hastalar item in patients)
            {
                if (item.HastaEmail == login.EMail)
                {
                    if (item.HastaSifre == login.Sifre)
                    {
                        return(item.TcNo);
                    }
                    else
                    {
                        return("Şifre Yanlış");
                    }
                }
            }
            return("Mail Yanlış");
        }
Ejemplo n.º 24
0
        public async Task <string> Auth(LoginDTO model)
        {
            var authResult = await _client.Login(model);

            //if()



            /*HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "token");
             * request.Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
             * HttpResponseMessage response = await _client.SendAsync(request);*/


            /* var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
             * var respose = await _client.PostAsync("/token", content);
             * var stringContent = await respose.Content.ReadAsStringAsync();
             * var resultModel = JsonConvert.DeserializeObject<AuthResultModel>(stringContent);*/

            return(authResult.Token);
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Login([FromBody] LoginDTO login)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _component.Login(_mapper.Map <LoginModel>(login));

            if (!result.Succeeded)
            {
                return(BadRequest("Credentials are not correct"));
            }

            return(Ok(new
            {
                token = result.Token,
                employeeId = login.EmployeeId
            }));
        }
Ejemplo n.º 26
0
        public LoginDTO CreateLogin(LoginDTO loginDTO)
        {
            var login = new Login
            {
                Name        = loginDTO.Name,
                Gender      = loginDTO.Gender,
                Email       = loginDTO.Email,
                PhoneNumber = loginDTO.PhoneNumber,
                Password    = loginDTO.Password,
                Roleid      = loginDTO.Roleid
            };

            _context.Logins.Add(login);
            _context.SaveChangesAsync();

            int loginid = login.LoginId;

            return
                (loginDTO);
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Session[sessionNames.userID_StudentOstad] == null)
            {
                Response.Redirect("~/CommonUI/login.aspx");
            }
            else
            {
                Session["CountUnRead"]   = null;
                Session["ContactUnread"] = null;
                LoginBusiness         logBusiness = new LoginBusiness();
                System.Data.DataTable dt          = new System.Data.DataTable();
                string userId = Session[sessionNames.userID_StudentOstad].ToString();
                user.Text = userId;
                //if (Request.QueryString["Flag_Grp"] != null )
                //{
                MessageJs.DeleteUnreadStudent(userId, Request.QueryString["Flag_Grp"] != null? Request.QueryString["Flag_Grp"]: "True",
                                              Request.QueryString["Flag_Grp"] != null && Request.QueryString["Flag_Grp"].Trim() != "True" && Request.QueryString["IdGrpOrPerson"] != null
                    ? Request.QueryString["IdGrpOrPerson"] :"-1");
                // }
                if (!IsPostBack)
                {
                    StuImg st = logBusiness.User_Img(Session[sessionNames.userID_StudentOstad].ToString());
                    PersonalImage.DataValue = st.img;
                    LoginDTO stInfo = logBusiness.Get_StInfo(Session[sessionNames.userID_StudentOstad].ToString());
                    stName.InnerText = stInfo.Name + " " + stInfo.LastName;


                    DataTable dtCountUnread;
                    DataTable dtUnReadContact;
                    dtCountUnread = MsgUnReadStudentBuisnes.GetUnReadMsgCountStudent(userId);

                    if (dtCountUnread != null && dtCountUnread.Rows.Count > 0)
                    {
                        Session["CountUnRead"] = dtCountUnread.Rows[0]["CountUnRead"].ToString();
                        dtUnReadContact        = MsgUnReadStudentBuisnes.GetUnReadMsgStudent(userId);
                        Session.Add("ContactUnread", dtUnReadContact);
                    }
                }
            }
        }
Ejemplo n.º 28
0
        public async Task <object> FindByLogin(LoginDTO user)
        {
            var baseUser = new UserEntity();

            if (user == null || string.IsNullOrWhiteSpace(user.Email))
            {
                return(new
                {
                    authenticated = false,
                    message = "Falha ao autenticar."
                });
            }

            baseUser = await repository.FindByLogin(user.Email);

            if (baseUser == null)
            {
                return(new
                {
                    authenticated = false,
                    message = "Falha ao autenticar."
                });
            }

            var identity = new ClaimsIdentity(
                new GenericIdentity(baseUser.Email),
                new[]
            {
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(JwtRegisteredClaimNames.UniqueName, baseUser.Email)
            }
                );

            var createDate     = DateTime.Now;
            var expirationDate = createDate + TimeSpan.FromSeconds(tokenConfigurations.Seconds);

            var handler = new JwtSecurityTokenHandler();
            var token   = CreateToken(identity, createDate, expirationDate, handler);

            return(SucessObject(createDate, expirationDate, token, user));
        }
Ejemplo n.º 29
0
        private void btOk_Click(object sender, EventArgs e)
        {
            string user, pass, passNewRepeat;

            user          = txtTaikhoan.Text;
            pass          = txtMatkhau.Text;
            passNewRepeat = txtNhapLaiMatKhau.Text;
            LoginDTO login = new LoginDTO(user, pass);

            if (pass != passNewRepeat)
            {
                label7.Text = "Mật khẩu mới nhập nhập lại không đúng!";
            }
            else
            {
                try
                {
                    int rl = loginBUS.InsertAccount(login);
                    if (rl > 0)
                    {
                        MessageBox.Show("Đăng ký tài khoản thành công");
                        this.Visible = false;
                        frmDangNhap fr = new frmDangNhap();
                        fr.Show();
                    }
                    else
                    {
                        MessageBox.Show("Tài khoản hoặc mật khẩu không hợp lệ! \n");
                        txtTaikhoan.Text = "";
                        txtMatkhau.Text  = "";

                        txtNhapLaiMatKhau.Text = "";
                        txtTaikhoan.Focus();
                    }
                }
                catch (SqlException)
                {
                    MessageBox.Show("Tài Khoản này đã tồn tại! \n");
                }
            }
        }
        public async Task <bool> LogInPerson()
        {
            try
            {
                //test
                //https://localhost:5001/person/login

                LoginDTO login = new LoginDTO
                {
                    Email    = Email,
                    Password = Passwoord
                };
                LocalSettings.Values["current_user_email"] = Email;
                HttpResponseMessage response = await AccountController.Login(login);

                if (response.IsSuccessStatusCode)
                {
                    var token = await response.Content.ReadAsStringAsync();

                    LocalSettings.Values["token"] = token;
                    Person loggedInUser = await AccountController.GetPersonByEmail(login.Email);

                    if (loggedInUser != null)
                    {
                        LocalSettings.Values["loggedInUser"] = loggedInUser.Name;
                    }
                    GotDataNotSuccesfull = false;
                }
                else
                {
                    GotDataNotSuccesfull = true;
                    ErrorMessage         = "Er liep iets mis bij het inloggen. Zijn alle parameters juist ingevuld?";
                }
            }
            catch (Exception)
            {
                ErrorMessage         = "Er liep iets mis bij het inloggen. Zijn alle parameters juist ingevuld?";
                GotDataNotSuccesfull = true;
            }
            return(GotDataNotSuccesfull);
        }