public ServerResponseInformation Authorize(ClientLoginModel clientLogin)
 {
     if (!_authorizeService.CheckLogin(clientLogin.Login))
     {
         return new ServerResponseInformation
                {
                    Status         = 2,
                    SerializedData = "Bad Login"
                }
     }
     ;
     else if (!_authorizeService.CheckAuthorize(clientLogin.Login, clientLogin.Password))
     {
         return new ServerResponseInformation
                {
                    Status         = 2,
                    SerializedData = "Bad Password"
                }
     }
     ;
     else
     {
         return(null);
     }
 }
Exemple #2
0
 public ClientLoginModel Login(ClientLoginModel model)
 {
     try
     {
         using (var cxt = new DataContext())
         {
             var data = cxt.dbCustomer.Where(x => x.Email.Equals(model.Email) &&
                                             x.Password.Equals(model.Password) &&
                                             x.IsActive)
                        .Select(x => new ClientLoginModel
             {
                 Email       = x.Email,
                 DisplayName = x.Name,
                 Password    = x.Password,
                 IsAdmin     = x.IsAdmin,
             })
                        .FirstOrDefault();
             return(data);
         }
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("Login", ex);
     }
     return(null);
 }
Exemple #3
0
 public ServerResponseInformation RecieveComputerHardwareInformation
     (ComputerHardwareInformationDTO computeHardwareInformation, ClientLoginModel clientLogin)
 {
     try
     {
         _computerComponentService.UpdateProcessor
             (clientLogin.Login, computeHardwareInformation.Processor);
         _computerComponentService.UpdateMotherBoard
             (clientLogin.Login, computeHardwareInformation.MotherBoard);
         _computerComponentService.UpdateVideoCards
             (clientLogin.Login, computeHardwareInformation.VideoCards);
         _computerComponentService.UpdateDiskDrives
             (clientLogin.Login, computeHardwareInformation.DiskDrives);
         _computerComponentService.UpdatePhysicalMemories
             (clientLogin.Login, computeHardwareInformation.PhysicalMemories);
         return(new ServerResponseInformation
         {
             Status = 1,
             SerializedData = "Success"
         });
     }
     catch (ServerServicesException exception)
     {
         return(new ServerResponseInformation
         {
             Status = -1,
             SerializedData = exception.Message
         });
     }
 }
        public ActionResult SignIn(ClientLoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.Password = CommonHelper.Encrypt(model.Password);
            var result = _factory.Login(model);

            if (result != null)
            {
                UserSession userSession = new UserSession();
                userSession.Email         = result.Email;
                userSession.UserName      = result.DisplayName;
                userSession.IsAdminClient = result.IsAdmin;
                Session.Add("UserClient", userSession);
                string     myObjectJson = JsonConvert.SerializeObject(userSession); //new JavaScriptSerializer().Serialize(userSession);
                HttpCookie cookie       = new HttpCookie("UserClientCookie");
                cookie.Expires = DateTime.Now.AddMonths(1);
                cookie.Value   = Server.UrlEncode(myObjectJson);
                HttpContext.Response.Cookies.Add(cookie);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("Email", "Thông tin tài khoản không chính xác");
                return(View(model));
            }
        }
Exemple #5
0
        public async Task <ClientLoginModel> Login(ClientLoginModel loginModel, [FromServices] ShellConfiguration shellConfiguration)
        {
            if (shellConfiguration.NeedAuthorization && (string.IsNullOrWhiteSpace(loginModel.Captcha) || HttpContext.Session.GetString(nameof(ClientLoginModel.Captcha)) != loginModel.Captcha.ToLowerInvariant()))
            {
                loginModel.Status  = LoginStatus.Failed;
                loginModel.Message = "Wrong captcha";
            }
            else
            {
                var user = ShellConfiguration.Users.FirstOrDefault(u => !shellConfiguration.NeedAuthorization || u.UserName == loginModel.UserName && u.Password == loginModel.Password);

                if (user == null)
                {
                    loginModel.Status  = LoginStatus.Failed;
                    loginModel.Message = "Wrong username or password";
                }
                else
                {
                    loginModel.Status = LoginStatus.Succesful;

                    var claims = new[]
                    {
                        new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                        new Claim(ClaimTypes.Name, user.UserName)
                    };

                    var identity   = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    var principal  = new ClaimsPrincipal(identity);
                    var properties = new AuthenticationProperties();

                    if (loginModel.Persist)
                    {
                        properties.IsPersistent = true;
                        properties.ExpiresUtc   = DateTime.UtcNow.AddMonths(12);
                    }

                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, properties);
                }
            }

            HttpContext.Session.Remove(nameof(ClientLoginModel.Captcha));
            return(loginModel);
        }
        public ClientLogin GetClient(ClientLoginModel client)
        {
            var clientFromDb = this.clientRepository.GetClientByUsername(client.Username);

            if (clientFromDb == null)
            {
                // No such username
                return(null);
            }

            var actualPasswordHash = PasswordUtilities.GeneratePasswordHash(client.Password, clientFromDb.PasswordSalt);

            if (actualPasswordHash != clientFromDb.PasswordHash)
            {
                // Password doesn't match the record in the database
                return(null);
            }

            return(clientFromDb);
        }
        public ActionResult Login(ClientLoginModel client)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(client));
            }

            var actualClient = this.clientManager.GetClient(client);

            if (actualClient == null)
            {
                this.ModelState.AddModelError("Form", "The username and / or password are incorrect");
                return(this.View(client));
            }
            else
            {
                this.Session[AuthConstants.SessionUserKey] = actualClient;
                return(this.RedirectToAction("Index", "Orders"));
            }
        }
 public ServerResponseInformation RecieveProcesses
     (IEnumerable <ProcessDTO> processes, ClientLoginModel clientLogin)
 {
     try
     {
         _processService.UpdateProcesses(clientLogin.Login, processes);
         return(new ServerResponseInformation
         {
             Status = 1,
             SerializedData = "Success"
         });
     }
     catch (ServerServicesException exception)
     {
         return(new ServerResponseInformation
         {
             Status = -1,
             SerializedData = exception.Message
         });
     }
 }
Exemple #9
0
 public ServerResponseInformation RecieveComputerSystemInformation
     (ComputerSystemDTO computerSystem, ClientLoginModel clientLogin)
 {
     try
     {
         _computerSystemService.UpdateComputerSystem(clientLogin.Login, computerSystem);
         return(new ServerResponseInformation
         {
             Status = 1,
             SerializedData = "Success"
         });
     }
     catch (ServerServicesException exception)
     {
         return(new ServerResponseInformation
         {
             Status = -1,
             SerializedData = exception.Message
         });
     }
 }
Exemple #10
0
 public ServerResponseInformation RecieveComputerOperatingInformation
     (ComputerOperatingInformationDTO computerOperatingInformation, ClientLoginModel clientLogin)
 {
     try
     {
         _computerSystemService.UpdateComputerSystem(clientLogin.Login, computerOperatingInformation.ComputerInformation);
         _processService.UpdateProcesses(clientLogin.Login, computerOperatingInformation.CurrentProcesses);
         return(new ServerResponseInformation
         {
             Status = 1,
             SerializedData = "Success"
         });
     }
     catch (ServerServicesException exception)
     {
         return(new ServerResponseInformation
         {
             Status = -1,
             SerializedData = exception.Message
         });
     }
 }
 public ClientLoginModel Login(ClientLoginModel model)
 {
     try
     {
         using (var cxt = new CMS_Context())
         {
             var data = cxt.CMS_Customer.Where(x => ((x.Email.Equals(model.Email) && x.Password == model.Password) ||
                                                     (!string.IsNullOrEmpty(model.Fb_ID) && (x.FbID == model.Fb_ID || x.GoogleID == model.Fb_ID))) &&
                                               x.IsActive.Value &&
                                               x.Status == (byte)Commons.EStatus.Actived
                                               )
                        .Select(x => new ClientLoginModel
             {
                 Email       = x.Email,
                 DisplayName = x.FirstName + " " + x.LastName,
                 Password    = x.Password,
                 IsAdmin     = false,
                 FirstName   = x.FirstName,
                 LastName    = x.LastName,
                 Phone       = x.Phone,
                 Id          = x.ID,
                 PostCode    = x.HomeZipCode,
                 Address     = x.HomeStreet,
                 Country     = x.HomeCountry,
                 City        = x.HomeCity,
             })
                        .FirstOrDefault();
             return(data);
         }
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("Login", ex);
     }
     return(null);
 }
Exemple #12
0
        public ActionResult FacebookLogin(string id, string firstname, string lastname, string fullname, string email, string picture)
        {
            FormsAuthentication.SetAuthCookie(email, false);
            ClientLoginModel model = new ClientLoginModel();

            model.Email   = email;
            model.Picture = picture;
            model.Fb_ID   = id;

            var obj = new
            {
                message = 1
            };
            bool IsCheck = _factory.CheckExistLoginSosial(id);

            if (IsCheck)
            {
                var resultLogin = _factory.Login(model);
                if (resultLogin != null)
                {
                    UserSession userSession = new UserSession();
                    userSession.Email         = resultLogin.Email;
                    userSession.UserName      = resultLogin.DisplayName;
                    userSession.IsAdminClient = resultLogin.IsAdmin;
                    userSession.FirstName     = resultLogin.FirstName;
                    userSession.LastName      = resultLogin.LastName;
                    userSession.Phone         = resultLogin.Phone;
                    userSession.Address       = resultLogin.Address;
                    userSession.UserId        = resultLogin.Id;
                    userSession.PostCode      = resultLogin.PostCode;
                    userSession.Country       = resultLogin.Country;
                    userSession.City          = resultLogin.City;
                    Session.Add("UserClient", userSession);
                    string     myObjectJson = JsonConvert.SerializeObject(userSession); //new JavaScriptSerializer().Serialize(userSession);
                    HttpCookie cookie       = new HttpCookie("UserClientCookie");
                    cookie.Expires = DateTime.Now.AddMonths(1);
                    cookie.Value   = Server.UrlEncode(myObjectJson);
                    HttpContext.Response.Cookies.Add(cookie);
                }
                else
                {
                    obj = new { message = 2 };
                    return(Json(obj, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                CustomerModels modelFB = new CustomerModels();
                modelFB.FbID      = id;
                modelFB.FirstName = firstname;
                modelFB.LastName  = lastname;
                modelFB.Email     = email;
                modelFB.ImageURL  = picture;
                string msg          = "";
                string cusId        = "";
                var    resultSignUp = _factory.CreateOrUpdate(modelFB, ref cusId, ref msg);
                if (resultSignUp)
                {
                    var         data        = _factory.GetDetail(cusId);
                    UserSession userSession = new UserSession();
                    userSession.Email     = data.Email;
                    userSession.UserName  = data.FirstName + " " + data.LastName;
                    userSession.FirstName = data.FirstName;
                    userSession.LastName  = data.LastName;
                    userSession.Phone     = data.Phone;
                    userSession.Address   = data.Address;
                    userSession.UserId    = data.ID;
                    userSession.PostCode  = data.Postcode;
                    userSession.Country   = data.Country;
                    userSession.City      = data.City;
                    Session.Add("UserClient", userSession);
                    string     myObjectJson = JsonConvert.SerializeObject(userSession); //new JavaScriptSerializer().Serialize(userSession);
                    HttpCookie cookie       = new HttpCookie("UserClientCookie");
                    cookie.Expires = DateTime.Now.AddMonths(1);
                    cookie.Value   = Server.UrlEncode(myObjectJson);
                    HttpContext.Response.Cookies.Add(cookie);
                }
                else
                {
                    obj = new { message = 3 };
                    return(Json(obj, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
Exemple #13
0
        // GET: ClientSite/Login
        public ActionResult SignIn()
        {
            ClientLoginModel model = new ClientLoginModel();

            return(View(model));
        }
Exemple #14
0
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = ConfigurationManager.AppSettings["FbAppId"],
                client_secret = ConfigurationManager.AppSettings["FbAppSecret"],
                redirect_uri  = RediredtUri.AbsoluteUri,
                code          = code
            });
            var accessToken = result.access_token;

            Session["AccessToken"] = accessToken;
            fb.AccessToken         = accessToken;
            dynamic me         = fb.Get("me?fields=link,first_name,currency,last_name,email,gender,locale,timezone,verified,picture,age_range");
            string  email      = me.email;
            string  first_name = me.first_name;
            string  last_name  = me.last_name;
            string  picture    = me.picture.data.url;
            string  fb_id      = me.id;

            FormsAuthentication.SetAuthCookie(email, false);
            ClientLoginModel model = new ClientLoginModel();

            model.Email     = email;
            model.FirstName = first_name;
            model.LastName  = last_name;
            model.Picture   = picture;
            model.Fb_ID     = fb_id;

            bool IsCheck = _factory.CheckExistLoginSosial(model.Fb_ID);

            if (IsCheck)
            {
                var resultLogin = _factory.Login(model);
                if (resultLogin != null)
                {
                    UserSession userSession = new UserSession();
                    userSession.Email         = resultLogin.Email;
                    userSession.UserName      = resultLogin.DisplayName;
                    userSession.IsAdminClient = resultLogin.IsAdmin;
                    userSession.FirstName     = resultLogin.FirstName;
                    userSession.LastName      = resultLogin.LastName;
                    userSession.Phone         = resultLogin.Phone;
                    userSession.Address       = resultLogin.Address;
                    userSession.UserId        = resultLogin.Id;
                    userSession.PostCode      = resultLogin.PostCode;
                    userSession.Country       = resultLogin.Country;
                    userSession.City          = resultLogin.City;
                    Session.Add("UserClient", userSession);
                    string     myObjectJson = JsonConvert.SerializeObject(userSession); //new JavaScriptSerializer().Serialize(userSession);
                    HttpCookie cookie       = new HttpCookie("UserClientCookie");
                    cookie.Expires = DateTime.Now.AddMonths(1);
                    cookie.Value   = Server.UrlEncode(myObjectJson);
                    HttpContext.Response.Cookies.Add(cookie);
                }
                else
                {
                    ModelState.AddModelError("Email", "Thông tin tài khoản không chính xác");
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                CustomerModels modelFB = new CustomerModels();
                modelFB.FbID      = fb_id;
                modelFB.FirstName = first_name;
                modelFB.LastName  = last_name;
                modelFB.Email     = email;
                modelFB.ImageURL  = picture;
                string msg          = "";
                string cusId        = "";
                var    resultSignUp = _factory.CreateOrUpdate(modelFB, ref cusId, ref msg);
                if (resultSignUp)
                {
                    var         data        = _factory.GetDetail(cusId);
                    UserSession userSession = new UserSession();
                    userSession.Email     = data.Email;
                    userSession.UserName  = data.FirstName + " " + data.LastName;
                    userSession.FirstName = data.FirstName;
                    userSession.LastName  = data.LastName;
                    userSession.Phone     = data.Phone;
                    userSession.Address   = data.Address;
                    userSession.UserId    = data.ID;
                    userSession.PostCode  = data.Postcode;
                    userSession.Country   = data.Country;
                    userSession.City      = data.City;
                    Session.Add("UserClient", userSession);
                    string     myObjectJson = JsonConvert.SerializeObject(userSession); //new JavaScriptSerializer().Serialize(userSession);
                    HttpCookie cookie       = new HttpCookie("UserClientCookie");
                    cookie.Expires = DateTime.Now.AddMonths(1);
                    cookie.Value   = Server.UrlEncode(myObjectJson);
                    HttpContext.Response.Cookies.Add(cookie);
                }
                else
                {
                    ModelState.AddModelError("Email", "");
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ClientCommandDTO HandleClientCommandRequest(ClientCommandRequest clientCommandRequest, ClientLoginModel clientLoginModel)
        {
            MethodInfo handleMethod
                = SearchHandleMethod(_classHandle, clientCommandRequest.Command);

            if (handleMethod == null)
            {
                throw new ClientCommandHandlerException("Undefined command.");
            }
            object clientCommand = handleMethod?.Invoke(this, new object[] { clientCommandRequest });

            if ((clientCommand is string) && !string.IsNullOrEmpty(((string)clientCommand)))
            {
                return(new ClientCommandDTO(
                           new ClientCommandInformation
                {
                    SerializedData = (string)clientCommand,
                    ClientLogin = clientLoginModel
                },
                           clientCommandRequest.Command
                           ));
            }
            else
            {
                throw new ClientCommandHandlerException("Error while forming command.");
            }
        }