예제 #1
0
 public ActionResult AdminUserCreate(Models.AdminUser adminuser)
 {
     adminuser.CreateTime = System.DateTime.Now;
     db.AdminUsers.Add(adminuser);
     db.SaveChanges();
     return(View());
 }
 public ActionResult AdminLogOut()
 {
     Session["AdminName"]  = new Models.AdminUser();
     Session["AdminLogin"] = "";
     Session["AdminMsg"]   = "";
     return(RedirectToAction("Login", "AdminPanel"));
 }
예제 #3
0
        public bool AddAdmin(Models.AdminUser user)
        {
            try
            {
                log.InfoFormat("AddAdmin");
                //Generate a temp password for the new user

                string newPassword = Guid.NewGuid().ToString();
                user.Password = Utils.base64Encode(newPassword);

                //Send email
                EmailHelper emailHelper = new EmailHelper();
                emailHelper.SendEmail(user.EmailAddress, "Welcome to MyGym!", String.Format("Hi {0}<br/> Please find your new credentials, <br/> Please login with {1}", user.Fullname, newPassword));



                IAdminRepository adminRepository = new AdminRepository();
                var result = adminRepository.CreateAdmin(user);

                if (result)
                {
                    SaveAccessLog(new AccessLog {
                        Username = UserSession.Current.Username, Operation = "ADD ADMIN", Details = string.Format("Adding new admin user {0}", user.Username), Type = "ADMIN"
                    });
                }

                return(result);
            }
            catch (Exception e)
            {
                log.ErrorFormat("AddAdmin {0}", e.ToString());
                throw;
            }
        }
예제 #4
0
 public Models.AdminUser CheckUser(Models.AdminUser user)
 {
     throw new NotImplementedException();
 }
        public ActionResult Login(Models.AdminUser Stu, string ReturnUrl = "")
        {
            string message = "";
            //if (!Pat.IsEmaiVerified)
            //{
            //    ViewBag.Message = "Please verify your email first";
            //    return View();
            //}


            var login = db.AdminUsers.Where(e => e.UserName == Stu.UserName).FirstOrDefault();


            //if (login.Count <= 0)
            //{
            //    //System.Threading.Thread.Sleep(4000);
            //    Session["AdminMsg"] = "Invalid User Name or Password";
            //    System.Threading.Thread.Sleep(10000);
            //    return View(Stu);
            //}

            if (login != null)
            {
                if (string.Compare(Crypto.Hash(Stu.Password), login.Password) == 0)
                {
                    //int timeout =/* Stu.RememberMe ?*/ 525600 : 20; // 525600 min = 1 year
                    //var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout);
                    //string encrypted = FormsAuthentication.Encrypt(ticket);
                    //var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                    //cookie.Expires = DateTime.Now.AddMinutes(timeout);
                    //cookie.HttpOnly = true;
                    //Response.Cookies.Add(cookie);



                    System.Threading.Thread.Sleep(5000);
                    //StudentRoll
                    Session["AdminName"] = login.UserName;

                    Session["AdminLogin"] = "******";
                    return(RedirectToAction("Index", "Orders"));
                }
                else
                {
                    message = "";
                }
            }
            else
            {
                System.Threading.Thread.Sleep(10000);
                message = "";
            }
            //SqlConnection con = null;
            //SqlCommand cmd = null;
            //try
            //{
            //    con = new SqlConnection();
            //    con.ConnectionString = @"Data Source=SQL5020.site4now.net;Initial Catalog=DB_A3F778_school;User Id=DB_A3F778_school_admin;Password=12@Arshuvocse;";
            //    cmd = new SqlCommand();
            //    cmd.Connection = con;
            //    con.Open();
            //    cmd.CommandText = "Update AdminInfo Set Attempt=Attempt+1";
            //    //cmd.CommandText = "insert into ClientIp(IpAddress, Date, Country) values('" + Request.UserHostAddress+"','"+DateTime.Now+"','"+ RegionInfo.CurrentRegion.DisplayName + "')";



            //    cmd.ExecuteNonQuery();
            //}
            //catch (Exception)
            //{
            //    throw;
            //}
            //finally
            //{
            //    if (con.State.Equals(ConnectionState.Open)) con.Close();
            //}

            //if (db.AdminInfoes.Sum(d => d.Attempt) >= 10)
            //{
            //    SendVerificationLinkEmailFotAlert();
            //    System.Threading.Thread.Sleep(90000);
            //}

            ViewBag.Message = message;
            return(View());
        }