Exemplo n.º 1
0
        //
        // GET: /Login/
        public ActionResult Login()
        {
            //get user credential
            string currentUserEmail = HttpContext.User.Identity.Name;

            if (currentUserEmail != "")
            {
                Icasie.Repositories.User user = new Repositories.User();

                using (IcasieEntities entity = new IcasieEntities())
                {
                    user = entity.Users.SingleOrDefault(c => c.Email == currentUserEmail);
                }

                switch (user.Role)
                {
                case Constant.Role.Author:
                    return(RedirectToAction("Index", "Submission"));

                case Constant.Role.Participant:
                    return(RedirectToAction("Index", "Participant"));

                default:
                    return(RedirectToAction("Index", "Conference"));
                }
            }

            return(View());
        }
Exemplo n.º 2
0
        public HamrazmResult AddUser(Repositories.User user)
        {
            var result   = new HamrazmResult();
            var userName = GetUser(user);

            if (userName != null)
            {
                db.Entry(user).State = EntityState.Added;
                result.Message       = "کاربر تعریف شد";
                return(result);
            }

            result.IsChange = false;
            result.Message  = "کاربر تکراری میباشد";
            return(result);
        }
Exemplo n.º 3
0
        public ActionResult Login(ViewModelLogin login, bool captchaValid)
        {
            if (!ModelState.IsValid)
            {
                return(View(login));
            }

            Icasie.Repositories.User user = new Repositories.User();

            using (IcasieEntities entity = new IcasieEntities())
            {
                user = entity.Users.SingleOrDefault(c => c.Email == login.Email);
            }

            if (user != null && Helper.Helper.CreatePasswordHash(login.Password, user.Salt) == user.Password)
            {
                int timeout = Constant.CookieExpiration.Normal;
                var ticket  = new FormsAuthenticationTicket(1, user.Email, DateTime.Now, DateTime.Now.AddMinutes(timeout), true, user.Role);
                var cookie  = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));

                if (ticket.IsPersistent)
                {
                    cookie.Expires = ticket.Expiration;
                }

                Response.Cookies.Add(cookie);
            }
            else
            {
                TempData["Message"] = "User & Password combination cannot be found";

                return(View(login));
            }

            switch (user.Role)
            {
            case Constant.Role.Author:
                return(RedirectToAction("Index", "Submission"));

            case Constant.Role.Participant:
                return(RedirectToAction("Index", "Participant"));

            default:
                return(RedirectToAction("Index", "Conference"));
            }
        }
Exemplo n.º 4
0
        public HamrazmResult UpdateUser(Repositories.User user)
        {
            var result   = new HamrazmResult();
            var userName = GetUser(user);
            var data     = Encoding.ASCII.GetBytes(user.Password);

            user.UserName = userName.UserName;
            var md5            = new MD5CryptoServiceProvider();
            var md5data        = md5.ComputeHash(data);
            var hashedPassword = Encoding.UTF8.GetString(md5data);

            user.Password        = hashedPassword;
            db.Entry(user).State = EntityState.Modified;

            result.Message = "کاربر تعریف شدرمز عبور با موفقیت تغییر  یافت";
            return(result);
        }
Exemplo n.º 5
0
        public ActionResult ForgotPassword(ViewModelResetPassword model, bool captchaValid)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            User user = new Repositories.User();

            using (IcasieEntities entity = new IcasieEntities())
            {
                user = entity.Users.SingleOrDefault(c => c.Email.Equals(model.Email));

                if (user == null)
                {
                    TempData["message"] = "We are not recognized the email you entered";
                    return(View());
                }


                ResetPassword reset = new ResetPassword();

                var rawToken = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                reset.Token   = rawToken.Replace("/", "");
                reset.UserId  = user.UserId;
                reset.ExpDate = DateTime.Now;

                entity.ResetPasswords.Add(reset);
                entity.SaveChanges();

                System.Threading.Tasks.Task.Run(() => EmailHelper.SendEmailPasswordReset(user.Email, user.FirstName + " " + user.LastName, reset.Token));
            }


            return(View("ResetPasswordSuccess"));
        }
Exemplo n.º 6
0
        public AjaxResponse Update([FromBody]UpdateUserRequest request, string userid)
        {
            if (request == null)
            {
                throw new BadRequestException();
            }

            var response = new AjaxResponse();
            UserBusiness ub = new UserBusiness();

            try
            {
                if ("Administrator".Equals(userid, StringComparison.OrdinalIgnoreCase))
                {
                    response.IsSuccess = false;
                    response.Message = "不能修改Administrator密码。";
                    return response;
                }
                var user = ub.GetUser(userid);

                // 2 means 客户端用户
                if (user.UserType == 2)
                {
                    response.IsSuccess = false;
                    response.Message = "终端用户没有权限修改密码。";
                    return response;
                }

                UserRepository ur = new UserRepository();
                User dbUser = new Repositories.User();
                dbUser.UserName = userid;
                dbUser.FullName = request.Name;
                dbUser.Phone = request.Phone;
                dbUser.City = request.City;
                dbUser.Description = request.Description;

                ur.UpdateUser(dbUser);
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message = ex.Message;
            }

            return response;
        }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="userName"></param>
 /// <param name="pasword"></param>
 /// <returns></returns>
 public Repositories.User GetUser(Repositories.User user)
 {
     return(db.Users.AsNoTracking().FirstOrDefault(a => (a.UserName.ToLower() == user.UserName && a.Password == user.Password) || a.UserId == user.UserId));
 }