예제 #1
0
        public bool Authenticate(string username, string password)
        {
            var passwordFromDbDecrypted = EncryptDecryptData.Decrypt(Password);

            if (UserName == username && password == passwordFromDbDecrypted)
            {
                return(true);
            }
            return(false);
        }
예제 #2
0
 public JsonResult Users()
 {
     if (Session != null && Session["AccountType"].ToString().Equals(AccountType.Admin))
     {
         var result = _coreContext.Users.ToList().Where(e => !e.AccountType.Equals(AccountType.Admin));
         result.ToList().ForEach((user) =>
         {
             user.Password = EncryptDecryptData.Decrypt(user.Password);
         });
         return(Json(result, JsonRequestBehavior.AllowGet));
     }
     return(Json("User is not admin", JsonRequestBehavior.AllowGet));
 }
예제 #3
0
 public string DecryptPassword()
 {
     return(EncryptDecryptData.Decrypt(Password));
 }
예제 #4
0
        public ActionResult Login(User user)
        {
            try
            {
                var users       = _coreContext.Users.ToList();
                var currentUser = users.FirstOrDefault(e => e.Name == user.Name);

                if (currentUser == null)
                {
                    return(Json(new { Message = "User does not exists, Please register" }));
                }
                else if (EncryptDecryptData.Decrypt(currentUser.Password) == user.Password)
                {
                    Session["AccountType"] = currentUser.AccountType;
                    Session["AccountId"]   = currentUser.AccountId;

                    if (currentUser.AccountType.Equals(AccountType.Admin))
                    {
                        return(Json(new { Status = "Success", Link = "/Account/Register" }));
                    }

                    var adminUser = users.FirstOrDefault(e => e.AccountType.Equals(AccountType.Admin));
                    adminUser.CheckForAccountValidity();
                    Session["AdminUser"] = adminUser;
                    using (var accountContext = new MahadevHWContext())
                    {
                        var profile      = accountContext.Profiles.FirstOrDefault();
                        var billSettings = accountContext.BillingSettings.FirstOrDefault();
                        if (billSettings == null)
                        {
                            var data = new BillingSetting()
                            {
                                IsDiscountRequired = true,
                                IsGstRate          = true,
                                IsHSNRequired      = true,
                                IsPerRequired      = true,
                                BillColumn         = "Price",
                                ProductColumn      = "SellPrice"
                            };
                            accountContext.BillingSettings.Add(data);
                            accountContext.SaveChanges();
                        }
                        if (profile != null)
                        {
                            Session["Profile"] = profile;
                        }
                        else
                        {
                            // new account is created from admin, inject the profile data from corecontext to GSTBillingContext
                            var profileFromAdminUser = new Profile
                            {
                                Address          = currentUser.Address,
                                BusinessName     = currentUser.BusinessName,
                                Email            = currentUser.Email,
                                GSTIN            = currentUser.GSTIN,
                                MobileNumber     = currentUser.MobileNumber,
                                Owner            = currentUser.Owner,
                                EnableStockCount = currentUser.EnableStockCount,
                                State            = currentUser.State,
                                StateCode        = currentUser.StateCode
                            };
                            Session["Profile"] = profileFromAdminUser;
                            accountContext.Profiles.Add(profileFromAdminUser);
                            accountContext.SaveChanges();
                        }
                    }
                    return(Json(new { Status = "Success", Link = "/Billing/New" }));
                }
                else
                {
                    return(Json(new { Status = "Failure", Message = "Incorrect Password." }));
                }
            }
            catch (System.Exception ex)
            {
                return(Json(new { Status = "Failure", Message = "Incorrect Password." }));
            }
        }