Example #1
0
        public async Task<ActionResult> Registration(RegisterViewModel register)
        {
            var sites = await SiteRepository.GetAllAsync();
            if (!ModelState.IsValid)
            {
                register.Sites = sites;
                return View(register);
            }

            //Check email exist in system
            var user = UserRepository.CheckExistEmail(register.Email);
            if (user != null)
            {
                ModelState.AddModelError("EXISTED", "Email eixsted in system, Please enter email!");
                register.Sites = sites;
                return View(register);
            }

            SYSUsersDto add = new SYSUsersDto();
            add.Email = register.Email;
            add.Firstname = register.FirstName;
            add.Lastname = register.LastName;
            add.PasswordHash = register.Password;
            add.SiteId = register.SiteId;
            add.DepartmentId = 1;//Enginner
            add.RoleId = (int)RoleType.REQUESTOR;
            add.RecoverPass = null;
            add.IsComfiredEmail = false;
            add.IsLocked = false;
            add.RegistedDate = DateTime.Now;
            add.Salt = "My1stC#MVCProject2015";
            add.LastLoginDate = null;
            add.LastUpdatedBy = "MySelf";
            add.Guid = Guid.NewGuid().ToString() + "-" + Guid.NewGuid().ToString();

            var result = await UserRepository.AddAsync(add);
            if (result == Model.SaveResult.SUCCESS)
            {
                //TODO SendMail
                string link = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "") + Url.Action("ConfirmRegister", new { guid = add.Guid });
                try
                {
                    Mail.SendRegister(register.Email, "[FASTrack] Confirm Register", link);
                }
                catch (Exception ex)
                {
                    LogService.Error(ex.Message, ex);
                }

                return RedirectToAction("LogIn", "Account");
            }
            else
            {
                register.Sites = sites;
                return View(register);
            }
        }
Example #2
0
        public async Task<ActionResult> Unlocked(int id, SYSUsersDto user)
        {
            if (id == 0)
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            if (ModelState.IsValid)
            {
                var result = await UserRepository.UnlockedAsync(user.Id);
                if (result == Model.SaveResult.SUCCESS)
                    return RedirectToAction("List");
            }

            return View(user);
        }