public async Task <Result <bool> > RegisterAsync(InputRegisterModel model)
        {
            if (model is null)
            {
                return(EMPTY_FORM);
            }

            var user = new ApplicationUser {
                Email = model.Email, UserName = model.Username
            };
            var result = await this.userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(Result <bool> .Failure(result.Errors.Select(e => e.Description)));
            }

            var messageData = new UserRegisteredMessage
            {
                Email  = user.Email,
                Name   = user.UserName,
                UserId = user.Id
            };

            var message = new Message(messageData);

            await this.messageService.SaveAsync(message);

            await this.publisher.Publish(messageData);

            await this.messageService.MarkMessageAsPublishedAsync(message.Id);

            return(Result <bool> .SuccessWith(true));
        }
Exemplo n.º 2
0
        public int UpdateUser(InputRegisterModel inputModel)
        {
            try
            {
                int USerId       = inputModel.UserId;
                var ExistingUser = (from S in Entity.Tbl_User where S.Id == inputModel.UserId select S).FirstOrDefault();
                if (ExistingUser != null)
                {
                    ExistingUser.IsNGO     = inputModel.IsNGO;
                    ExistingUser.DPPath    = !(string.IsNullOrEmpty(inputModel.DPPath)) ? inputModel.DPPath : "";
                    ExistingUser.FirstName = !(string.IsNullOrEmpty(inputModel.FirstName)) ? inputModel.FirstName : "";
                    ExistingUser.LastName  = !(string.IsNullOrEmpty(inputModel.LastName)) ? inputModel.LastName : "";
                    string initial = "";
                    initial = !(string.IsNullOrEmpty(inputModel.FirstName)) ? inputModel.FirstName : "";
                    initial = initial + (!(string.IsNullOrEmpty(inputModel.LastName)) ? inputModel.LastName : "");

                    ExistingUser.Name       = initial;
                    ExistingUser.CanEndorse = inputModel.canEndorse;
                    ExistingUser.UpdatedOn  = DateTime.Now;
                    Entity.SaveChanges();
                    //ExistingUser.UpdatedBy=inputModel.
                    if (inputModel.IsNGO)
                    {
                        AddNGOModelUser(inputModel);
                    }
                    else
                    {
                        RemoveNGOUser(inputModel);
                    }
                }
                return(USerId);
            }
            catch (Exception ex)
            { throw ex; }
        }
Exemplo n.º 3
0
        public async Task <ActionMessage> CreateAccount(InputRegisterModel model, byte[] image)
        {
            ActionMessage response = new ActionMessage();

            User dbUser = await userManager.FindByNameAsync(model.Username);

            if (dbUser == null)
            {
                User user = new User();
                user.Email     = model.Email;
                user.UserName  = model.Username;
                user.UserImage = image;

                IdentityResult result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    response.Message = "Account successfully created";
                }
            }
            else
            {
                response.Error = "Create failed!! Username already exists";
            }

            return(response);
        }
Exemplo n.º 4
0
        public HttpResponseMessage CheckOTP([FromBody] InputRegisterModel Model)
        {
            try
            {
                InputRegisterModel m    = new InputRegisterModel();
                var            res      = IService.CheckOTP(Model);
                ResponseObject response = new ResponseObject();

                if (res == "Successfully Updated!")
                {
                    response.userId      = Model.UserName.ToString();
                    response.ResponseMsg = "Registered Successfully. Please try logging in!";
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                else
                {
                    response.userId      = Model.UserName.ToString();
                    response.ResponseMsg = res;
                    return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, response));
                }
            }
            catch (Exception ex)
            {
                ResponseObject response = new ResponseObject();
                response.ExceptionMsg = ex.InnerException.ToString();
                response.ResponseMsg  = "Registeration with OTP  is ended with an exception";
                response.ErrorCode    = HttpStatusCode.InternalServerError.ToString();
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }
        public async Task <ActionResult> Register([FromBody] InputRegisterModel model)
        {
            var result = await this.identityService.RegisterAsync(model);

            if (!result.Succeeded)
            {
                this.logger.LogInformation("Invalid registration.");
                return(BadRequest(result.Errors));
            }

            this.logger.LogInformation($"Registered new user: {model.Username}");
            return(this.Ok());
        }
Exemplo n.º 6
0
        public ResponseModel <User> Register(InputRegisterModel inputRegisterModel, string password)
        {
            string passwordHash, passwordSalt;
            // HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
            var user = new User
            {
                Email     = inputRegisterModel.Email,
                FirstName = inputRegisterModel.FirstName,
                LastName  = inputRegisterModel.LastName,
                Phone     = inputRegisterModel.Phone,
            };

            responseModel.Success = _userDal.Add(user);
            return(responseModel);
        }
Exemplo n.º 7
0
 public bool RemoveNGOUser(InputRegisterModel reg)
 {
     try
     {
         UserModel um     = new UserModel();
         var       result = (from S in Entity.tbl_UserNGOEndorsement where S.UserId == reg.UserId select S).FirstOrDefault();
         if (result != null)
         {
             Entity.tbl_UserNGOEndorsement.Remove(result);
             Entity.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     { throw ex; }
 }
        public async Task <IActionResult> Register(InputRegisterModel model, string userImage)
        {
            if (ModelState.IsValid)
            {
                byte[]        image    = ImageToByteConverter.Convert(userImage);
                ActionMessage response = await userService.CreateAccount(model, image);

                if (User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("ActionMessage", "Dashboard", response));
                }
                else
                {
                    return(RedirectToAction("Login", "Auth"));
                }
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public async Task <JsonResult> Register([FromBody] InputRegisterModel inputRegisterModel)
        {
            if (inputRegisterModel.UserName.IsNullOrWhiteSpace())
            {
                return(AjaxHelper.JsonResult(HttpStatusCode.BadRequest, "用户名不能为空"));
            }
            //检查用户名是否重复
            bool isExist = await _userService.CheckUserNameDupAsync(inputRegisterModel.UserName);

            if (isExist)
            {
                return(AjaxHelper.JsonResult(HttpStatusCode.Found, "用户名已存在"));
            }
            if (inputRegisterModel.Password.IsNullOrWhiteSpace())
            {
                return(AjaxHelper.JsonResult(HttpStatusCode.BadRequest, "密码不能为空"));
            }
            string salt    = new Random().Next(100000, 999999).ToString();
            var    userDto = new UserDto
            {
                UserName = inputRegisterModel.UserName,
                RealName = inputRegisterModel.RealName,
                Password = (inputRegisterModel.Password.ToMd5() + salt).ToMd5(),
                Salt     = salt
            };

            if (inputRegisterModel.RegisterType == RegisterType.Assign)
            {
                userDto.UserRoles = inputRegisterModel.Roles.Select(i => new UserRoleDto {
                    User = userDto, RoleId = i
                }).ToList();
                string token  = HttpContext.Request.Headers["token"];
                var    userId = (await LoginManager.GetUserIdAsync(token)).GetValueOrDefault();
                userDto.CreatorUserId = userId;
            }

            var id = await _userService.InsertAndGetIdAsync(userDto);

            return(AjaxHelper.JsonResult(HttpStatusCode.OK, "注册成功", id));
        }
Exemplo n.º 10
0
        public ResponseModel <User> Add([FromBody] InputRegisterModel user)
        {
            var result = new ResponseModel <User>();
            var x      = Guid.NewGuid().ToString();

            try
            {
                var userExists = _userManager.UserExists(user.Email);
                if (!userExists.Success)
                {
                    if (ModelState.IsValid)
                    {
                        User NewCat = new User()
                        {
                            FirstName      = user.FirstName,
                            LastName       = user.LastName,
                            Email          = user.Email,
                            PasswordSalt   = x,
                            Phone          = user.Phone,
                            HashedPassword = AuthManager.HashingHelper.CreatePasswordHash(user.Password, x)
                        };
                        result = _userManager.Add(NewCat);
                    }
                    else
                    {
                        result.Success = false;
                        result.result  = null;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 11
0
 public HttpResponseMessage Post([FromBody] InputRegisterModel inputModel)
 {
     try
     {
         ResponseObject response = new ResponseObject();
         var            identity = (ClaimsIdentity)User.Identity;
         var            claims   = identity.Claims.Select(x => new { type = x.Type, value = x.Value });
         var            userId   = claims.Where(a => a.type == "UserId").Select(a => a.value).SingleOrDefault().ToString();
         inputModel.UserId = Convert.ToInt32(userId);
         var result = userservice.UpdateUser(inputModel);
         response.userId      = result.ToString();
         response.ResponseMsg = "User Updated  successfully";
         return(Request.CreateResponse(HttpStatusCode.OK, response));
     }
     catch (Exception ex)
     {
         ResponseObject response = new ResponseObject();
         response.ExceptionMsg = ex.InnerException.ToString();
         response.ResponseMsg  = "User Updation is ended with an exception";
         response.ErrorCode    = HttpStatusCode.InternalServerError.ToString();
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
     }
 }
        public IActionResult Register()
        {
            InputRegisterModel model = new InputRegisterModel();

            return(View(model));
        }
Exemplo n.º 13
0
        public bool AddNGOModelUser(InputRegisterModel reg)
        {
            try
            {
                UserModel um     = new UserModel();
                var       result = (from S in Entity.tbl_UserNGOEndorsement where S.UserId == reg.UserId select S).FirstOrDefault();
                if (result == null)
                {
                    tbl_UserNGOEndorsement NewNGO = new tbl_UserNGOEndorsement();

                    NewNGO.NGORegisterationNO = string.IsNullOrEmpty(reg.RegisterationNo) ? "" : reg.RegisterationNo;
                    NewNGO.NGORegAt           = string.IsNullOrEmpty(reg.Registeredat) ? "" : reg.Registeredat;
                    if (reg.canEndorse)
                    {
                        if (!string.IsNullOrEmpty(reg.NGOSector))
                        {
                            StoryCategory cate        = (StoryCategory)Enum.Parse(typeof(StoryCategory), reg.NGOSector);
                            int           NGOSectorId = (int)cate;
                            NewNGO.NGOSector = NGOSectorId;
                        }
                        if (!string.IsNullOrEmpty(reg.NGOType))
                        {
                            NGOType NGOtype   = (NGOType)Enum.Parse(typeof(NGOType), reg.NGOType);
                            int     NGOTypeId = (int)NGOtype;
                            NewNGO.NGOType = NGOTypeId;
                        }
                    }

                    //NewNGO.StateId = reg.stateId;// string.IsNullOrEmpty(reg.stateId) ? -1: Convert.ToInt32(reg.stateId);

                    //NewNGO.CityId = reg.cityId;

                    //NewNGO.CountryId = reg.countryID;

                    NewNGO.CityName    = reg.cityName;
                    NewNGO.StateName   = reg.stateName;
                    NewNGO.CountryName = reg.countryName;
                    NewNGO.UserId      = reg.UserId;



                    Entity.tbl_UserNGOEndorsement.Add(NewNGO);
                    Entity.SaveChanges();
                    return(true);
                }
                else
                {
                    result.NGORegisterationNO = string.IsNullOrEmpty(reg.RegisterationNo) ? "" : reg.RegisterationNo;
                    result.NGORegAt           = string.IsNullOrEmpty(reg.Registeredat) ? "" : reg.Registeredat;
                    if (reg.canEndorse)
                    {
                        if (!string.IsNullOrEmpty(reg.NGOSector))
                        {
                            StoryCategory cate        = (StoryCategory)Enum.Parse(typeof(StoryCategory), reg.NGOSector);
                            int           NGOSectorId = (int)cate;
                            result.NGOSector = NGOSectorId;
                        }
                        if (!string.IsNullOrEmpty(reg.NGOType))
                        {
                            NGOType NGOtype   = (NGOType)Enum.Parse(typeof(NGOType), reg.NGOType);
                            int     NGOTypeId = (int)NGOtype;
                            result.NGOType = NGOTypeId;
                        }
                    }
                    else
                    {
                        result.NGOSector = 0;
                        result.NGOType   = 0;
                    }
                    result.CityName    = reg.cityName;
                    result.StateName   = reg.stateName;
                    result.CountryName = reg.countryName;
                    result.UserId      = reg.UserId;

                    Entity.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            { throw ex; }
        }