Пример #1
0
        public int LogIn(LogInParams _LogInViewModel)
        {
            try
            {
                UserService _userService = new UserService();
                string      _pass        = EncryptDecryptString.Encrypt(_LogInViewModel.Password, "Taj$$Key");
                var         _paramters   = new LogInParams()
                {
                    Username = _LogInViewModel.Username,
                    Password = _pass
                };

                List <UserViewModel> User_List = new List <UserViewModel>();
                User_List = _userService.Find(_paramters);
                if (User_List.Count <= 0)
                {
                    return(-1);
                }

                SessionHandler.Instance.Set(User_List, SessionEnum.User_Info); // Save User Session.
                return(1);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #2
0
        public HttpResponseMessage LogIn(LogInParams _LogInViewModel)
        {
            try
            {
                UserService _userService = new UserService();
                string      _pass        = EncryptDecryptString.Encrypt(_LogInViewModel.Password, "Taj$$Key");
                var         _paramters   = new LogInParams()
                {
                    Username = _LogInViewModel.Username,
                    Password = _pass
                };

                List <UserViewModel> User_List = new List <UserViewModel>();
                User_List = _userService.Find(_paramters);
                if (User_List.Count <= 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, -1));
                }

                SessionHandler.Instance.Set(User_List, SessionEnum.User_Info); // Save User Session.
                return(Request.CreateResponse(HttpStatusCode.OK, User_List));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #3
0
        public string RecoverPassoerd(string Email)
        {
            try
            {
                // check Email in our database or not.
                UserService _userService = new UserService();
                var         _paramters   = new LogInParams()
                {
                    Email = Email
                };

                List <UserViewModel> User_List = new List <UserViewModel>();
                User_List = _userService.Find(_paramters);
                if (User_List.Count <= 0)
                {
                    return("This email does not exsit in our database");
                }

                //---------------------------------------------------------------

                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                client.EnableSsl      = true;
                client.Host           = "smtp.gmail.com";
                client.Port           = 587;

                string AppEmail = EncryptDecryptString.Decrypt(ConfigurationManager.AppSettings["Email"], "Taj$$Key");
                string AppPass  = EncryptDecryptString.Decrypt(ConfigurationManager.AppSettings["EmailAuth"], "Taj$$Key");

                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(AppEmail, AppPass);
                client.UseDefaultCredentials = false;
                client.Credentials           = credentials;

                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.From = new MailAddress(AppEmail);
                msg.To.Add(new MailAddress(Email));

                msg.Subject = "Maskan Rest Password";

                msg.IsBodyHtml = true;
                string _pass = EncryptDecryptString.Encrypt(Email, "Taj$$Key");

                string CurrentUrl = "http://" + Request.Url.DnsSafeHost + ":" + Request.Url.Port + "/ResetPassword/restpass/" + _pass;
                // Email Body.
                string body = "Dear User <br />";
                body += "Please fllow this link to recover your passord </br>";
                body += "<a href =" + CurrentUrl + "> Maskan rest your Password </ a >  <br />";

                msg.Body       = body;
                msg.IsBodyHtml = true;

                client.Send(msg);

                return("Success");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Пример #4
0
        public HttpResponseMessage LogIn(LogInParams _LogInViewModel)
        {
            try
            {
                UserService _userService = new UserService();
                string      _pass        = EncryptDecryptString.Encrypt(_LogInViewModel.Password, "Taj$$Key");
                var         _paramters   = new LogInParams()
                {
                    Username = _LogInViewModel.Username,
                    Password = _pass
                };

                List <UserViewModel> User_List = new List <UserViewModel>();
                User_List = _userService.Find(_paramters);
                if (User_List.Count > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.Accepted, User_List));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "Invalid username or password"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #5
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

            ApplicationUser user = new ApplicationUser();

            UserService _userService = new UserService();
            string      _pass        = EncryptDecryptString.Encrypt(context.Password, "Taj$$Key");
            var         _paramters   = new LogInParams()
            {
                Username = context.UserName,
                Password = _pass
            };

            List <UserViewModel> User_List = new List <UserViewModel>();

            User_List = _userService.Find(_paramters);

            if (User_List.Count <= 0)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }
            user.UserName = User_List[0].UserFullName;
            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }

            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                OAuthDefaults.AuthenticationType);

            ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                  CookieAuthenticationDefaults.AuthenticationType);

            AuthenticationProperties properties = CreateProperties(user.UserName);
            AuthenticationTicket     ticket     = new AuthenticationTicket(oAuthIdentity, properties);

            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
        }