Beispiel #1
0
        public async Task <ActionResult> Create(CreateUserViewModel userViewModel)
        {//TODO Upload Profile image
            var newUser = userViewModel.CurrentUser;

            newUser.ProfileImagePath = "Default";
            newUser.UserTypeID       = (int)UserType.UserTypes.User;

            if (ModelState.IsValid)
            {
                if (_userManger.UserNameExists(userViewModel.CurrentUser.UserName))
                {
                    ViewBag.Message             = "Username is currently being used";
                    userViewModel.Genders       = _genderManager.GetAll();
                    userViewModel.Nationalities = _nationalityManager.GetAll();

                    return(View(nameof(Create), userViewModel));
                }
                else
                {
                    await _userManger.Add(newUser, userViewModel.Password);

                    var user = _userManger.Login(newUser.UserName, userViewModel.Password);

                    if (!(user is InvalidUser))
                    {
                        _sessionHelper.Add("CurrentUser", user);
                        return(RedirectToAction(nameof(EditIntegrations)));
                    }
                }
            }

            ViewBag.Message = "An error occurred when creating the account.";
            return(View(nameof(Create)));
        }
        public IActionResult AddUser(AddUserRequestVm addUserRequestVm)
        {
            var user = userManager.FindByUserEmailId(addUserRequestVm.UserEmailId);

            if (user != null)
            {
                return(Conflict());
            }

            var addedUser = userManager.Add(new UserDm
            {
                UserEmailId         = addUserRequestVm.UserEmailId,
                UserGender          = (short)addUserRequestVm.UserGender,
                UserEmailIdVerified = false,
                UserIsActive        = true
            });

            if (addedUser == null)
            {
                return(StatusCode(500));
            }

            if (!userManager.SendEmailVerificationLink(addedUser))
            {
                return(StatusCode(500));
            }

            return(Ok(addedUser));
        }
        public async Task <IActionResult> RegisterUser([FromBody] AddUserDto userDto)
        {
            if (userDto == null)
            {
                _logger.LogError("User Object cannot be zero or null");
                return(BadRequest(new ResponseMessages {
                    Message = "User is null ", status = "400"
                }));
            }
            var userEntity = _mapper.Map <User>(userDto);
            var userVal    = await _userManager.Add(userEntity);

            if (userVal != 0)
            {
                //var createdUser = _mapper.Map<AddUserDto>(userEntity);
                _logger.LogInfo($"New created user as login ID : {userEntity.LoginID}");
                //return CreatedAtRoute("UserById", new { userid = createdUser.userId }, createdUser);
                return(Ok(new ResponseMessages {
                    Message = "User Created Successfully", status = "200"
                }));
            }
            else
            {
                return(BadRequest(new ResponseMessages {
                    Message = "User Not Created ", status = "400"
                }));
            }
        }
        public void Initialize()
        {
            try
            {
                int count = 1;
                while (count <= 5)
                {
                    var result = _userManager.Add(new User {
                        StUserName = "******", StEmail = "*****@*****.**", InStatus = (int)StatusInfo.Active, StDescription = "TEST"
                    });
                    if (result.Succeeded)
                    {
                        count++;
                    }
                    else
                    {
                        throw new Exception("Kayıt Başarısız " + result.Desc);
                    }
                }

                var list = _userManager.GetAll();
                Assert.Equal(5, list.ToList().Count);
            }
            catch (Exception ex)
            {
            }
        }
        public async Task <IActionResult> RegisterUser(RegisterationModelForUsers registerationModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (await CheckIfUserExist(registerationModel.UserSecurity))
            {
                return(BadRequest());
            }

            registerationModel.UserInfo.UserAddress = registerationModel.Address;

            addressManager.Add(registerationModel.Address);
            dbContextUser.Add(registerationModel.UserInfo);

            string id = await AddUserToAspNetUsers(registerationModel.UserSecurity, registerationModel.UserInfo, "user");

            if (id != null)
            {
                string imagePath = UploadToCloudinary.UploadImageToCloudinary(registerationModel.UserInfo.ImagePath);

                if (imagePath != null)
                {
                    registerationModel.UserInfo.ImagePath     = imagePath;
                    registerationModel.UserInfo.AspNetUsersId = id;
                    dbContextUser.Complete();
                    return(Ok());
                }
            }
            return(BadRequest());
        }
        public Object Post([FromBody] User user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                else
                {
                    _userManager.Add(user);
                }

                return(Ok("Record created successfully"));
            }
            catch (WebException e)
            {
                string Message = "Exception Message :" + e.Message;
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    string statusCode        = "Status Code : " + ((HttpWebResponse)e.Response).StatusCode;
                    string statusDescription = "Status Description : " + ((HttpWebResponse)e.Response).StatusDescription;
                }
                throw new Exception(Message);
            }
            catch (Exception e)
            {
                string Message = "Exception Message :" + e.Message;
                throw new Exception(Message);
            }
        }
Beispiel #7
0
        public async Task <ActionResult> Registration(User user)
        {
            if (ModelState.IsValid)
            {
                if (manager.IsAlreadyRegister(user))
                {
                    user.RegDate  = DateTime.Now;
                    user.Cookie   = Guid.NewGuid().ToString();
                    user.IsActive = false;
                    user.Password = SecurityHelper.GetHashSha256(user.Password);
                    manager.Add(user);
                    try
                    {
                        await EmailHelper.SendMail(user);
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    return(RedirectToAction("ResultRegister"));
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким e-mail уже существует");
                }
            }
            return(View());
        }
Beispiel #8
0
 public ActionResult <string> Hola()
 {
     _userManager.Add(new User()
     {
         Name     = "Caquita",
         LastName = "Cacota"
     });
     return("holi");
 }
Beispiel #9
0
        public IActionResult Add(User user)
        {
            var result = _userManager.Add(user);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Beispiel #10
0
        public ActionResult Registration(User user)
        {
            if (Session["designation"].ToString() == "Admin")
            {
                user.Designation = "Organization Owner";
            }
            else if (Session["designation"].ToString() == "Organization Owner")
            {
                user.Designation = "Manager";
            }
            user.Approve      = true;
            user.AssetApprove = true;
            if (ModelState.IsValid)
            {
                if (userManager.IsExistUserName(user.UserName))
                {
                    ViewBag.Message = "This UserName Has Already Taken";
                }
                else
                {
                    if (userManager.Add(user))
                    {
                        ViewBag.Message = "Registration Successfull";
                        ModelState.Clear();
                    }
                    else
                    {
                        ViewBag.Message = "Registration Failed";
                        return(View(user));
                    }
                }
            }


            int    orgid    = 0;
            string username = Session["username"].ToString();

            if (Session["designation"].ToString() == "Organization Owner")
            {
                var uerlist = userManager.GetAll().Where(c => c.UserName == username);

                foreach (var t in uerlist)
                {
                    orgid = t.OrganizationId;
                }
                ViewBag.orglist = organizationManager.GetAll().Where(c => c.Id == orgid);
            }
            else
            {
                ViewBag.orglist = organizationManager.GetAll();
            }

            return(View());
        }
Beispiel #11
0
        public RedirectResult Register(string login, string password)
        {
            User newuser = new User
            {
                login    = login,
                password = password
            };

            users.Add(newuser);

            return(Redirect("/Lession/LessionList"));
        }
Beispiel #12
0
        public async Task <IActionResult> Register(User model, string PasswordConfirm)
        {
            if (!string.IsNullOrEmpty(model.Password) && model.Password == PasswordConfirm)
            {
                var settings = _settingsManager.Table().FirstOrDefault();

                _userManager.Add(model);

                var result = false;

                if (settings.MembershipEmailControl)
                {
                    model.Approve = false;
                    result        = await _mailExtension.SendMail(new MailInfoModel
                    {
                        MailTo  = model.Email,
                        Subject = "Mynotebook | Account activation",
                        Message = $"<a href='{settings.WebAddress}/account-activation?Username={model.Username}&Code={model.Email.SHA256Encrypt()}'>Activate</a>"
                    });
                }
                else
                {
                    model.Approve = true;
                }

                TempData["message"] = HelperMethods.ObjectConvertJson(new TempDataModel {
                    type = "success", message =
                        result ? "click on the link sent to your e-mail address to complete the membership process" : "Registration successful"
                });

                return(View("Login"));
            }

            TempData["message"] = HelperMethods.ObjectConvertJson(new TempDataModel {
                type = "error", message = "Passwords do not match"
            });
            return(View());
        }
Beispiel #13
0
 public virtual IHttpActionResult AddUser([FromBody] UserRequest userRequest)
 {
     try
     {
         return(Ok(_users.Add(
                       userRequest.Identity,
                       userRequest.Secret,
                       userRequest.Roles)));
     }
     catch (UserException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Beispiel #14
0
 public ActionResult AddUser(UserDTO u)
 {
     if (ModelState.IsValid)
     {
         var user = mapper.Map <user>(u);
         var ID   = userManager.Add(user, u.password, key.KeyForPassword);
         if (ID > 0)
         {
             userManager.AddRole(user.id, "Admin");
         }
         return(StatusCode(201));
     }
     return(BadRequest());
 }
        private static void GenerateData(int count, IUserManager manager)
        {
            List <User> users = new Faker <User>()
                                .RuleFor(u => u.Id, f => f.UniqueIndex)
                                .RuleFor(u => u.Email, f => f.Internet.Email())
                                .RuleFor(u => u.Hobby, f => f.Commerce.Department())
                                .RuleFor(u => u.Age, f => f.Random.Int(1, 100))
                                .Generate(count);

            foreach (var item in users)
            {
                Console.Write("\nUser:"******"user");
            }
        }
Beispiel #16
0
        public IDataResult <User> Register(UserForRegisterDto userForRegisterDto, string password)
        {
            byte[] passwordHash, passwordSalt;
            HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
            var user = new User {
                Email        = userForRegisterDto.Email,
                FirstName    = userForRegisterDto.FirstName,
                LastName     = userForRegisterDto.LastName,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt,
                Status       = true
            };

            _userManager.Add(user);
            return(new SuccessDataResult <User>(user, Messages.UserRegistered));
        }
        public async Task <IHttpActionResult> Register(UserModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var mappedModel = Mapper.Map <UserDto>(model);
            var result      = await userManager.Add(mappedModel);

            if (result == null)
            {
                return(InternalServerError());
            }

            return(Ok(Mapper.Map <BaseUserModel>(result)));
        }
Beispiel #18
0
        public UserDT Register([FromBody] UserDT user)
        {
            IUserManager userManager = ObjectContainer.GetUserManager();

            User u = new User
            {
                Email         = user.Username,
                FullName      = user.FullName,
                SuperiorEmail = user.SuperiorEmail
            };

            userManager.GeneratePassword(u, user.Password);

            userManager.Add(u);

            return(Authenticate(user));
        }
Beispiel #19
0
        public ActionResult AddUser(AddUserViewModel addUserViewModel)
        {
            Response _resp = new Response()
            {
                Code = -1
            };

            if (ModelState.IsValid)
            {
                //检查用户名
                if (userManager.HasUserName(addUserViewModel.Username))
                {
                    _resp.Code    = 0;
                    _resp.Message = "用户名已存在";
                }
                //检查Email
                if (userManager.HasEmail(addUserViewModel.Email))
                {
                    _resp.Code    = 0;
                    _resp.Message = string.IsNullOrEmpty(_resp.Message) ? "Email已存在" : _resp.Message + "\n Email已存在";
                }
                if (_resp.Code == 0)
                {
                    return(Json(_resp));
                }
                //  User _user = Mapper.Map<User>(addUserViewModel);

                User _user = new User();
                _user.RoleID   = addUserViewModel.RoleID;
                _user.Username = addUserViewModel.Username;
                _user.Name     = addUserViewModel.Name;
                _user.Sex      = addUserViewModel.Sex;
                _user.Password = Security.SHA256(addUserViewModel.Password);
                _user.Email    = addUserViewModel.Email;
                _user.RegTime  = System.DateTime.Now;
                _resp          = userManager.Add(_user);
            }
            else
            {
                _resp.Code    = 0;
                _resp.Message = General.GetModelErrorString(ModelState);
            }

            return(Json(_resp));
        }
Beispiel #20
0
        private void btnNewUserCreate_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtNewUser.Text) && txtNewUser.Text.Length < 20)
            {
                _userManager.Add(new User {
                    Name = txtNewUser.Text
                });
                MessageBox.Show($"User {txtNewUser.Text} created");
            }
            else if (txtNewUser.Text.Length >= 20)
            {
                MessageBox.Show("User name can't be longer than 20 characters!");
            }
            else
            {
                MessageBox.Show("User name can't be empty!");
            }


            txtNewUser.Text = string.Empty;
        }
Beispiel #21
0
        public ActionResult Register(RegisterViewModel register)
        {
            #region 网站设置
            CustomCon custom  = (CustomCon)ConfigurationManager.GetSection("customCon");
            WebInfo   webInfo = custom.WebInfo;
            ViewBag.WebInfo = webInfo;
            #endregion

            if (userManager.HasUserName(register.UserName))
            {
                ModelState.AddModelError("UserName", "用户名已存在");
            }
            if (userManager.HasEmail(register.Email))
            {
                ModelState.AddModelError("Email", "Email已存在");
            }
            if (ModelState.IsValid)
            {
                User user = new User();
                if (TryUpdateModel(user))
                {
                    user.Password = Security.SHA256(register.Password);
                    user.RegTime  = DateTime.Now;
                    user.RoleID   = 1;
                    Response response = userManager.Add(user);
                    if (response.Code == 1)
                    {
                        user = response.Data;
                        CurrUser.Serialize(user.ID, user.Username);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.er = "注册失败:" + response.Message;
                    }
                }
            }
            ViewBag.er = "注册失败";
            return(View(register));
        }
Beispiel #22
0
        public ActionResult Registration(RegisterViewModel model)
        {
            try
            {
                var entity = Mapper.Map <RegisterViewModel, User>(model);
                var user   = _userManager.GetUserByEmail(model.Email);
                if (user != null)
                {
                    throw new Exception("лваолв");
                }

                var salt = PasswordHashing.GenerateSaltValue();
                var pass = PasswordHashing.HashPassword(entity.password, salt);
                entity.passwordSalt = salt;
                entity.password     = pass;
                entity.photo        = "/images/Account/account.jpg";
                _userManager.Add(entity);

                entity.roles = new List <UserInRoles>()
                {
                    new UserInRoles()
                    {
                        id_roles = 2, id_user = entity.id
                    }
                };
                _userManager.Update(entity);

                var url = Url.Action("ConfirmEmail", "Account", new { token = entity.id, email = entity.email },
                                     Request.Url.Scheme);
                _userManager.SentConfirmMail(entity, url);


                return(RedirectToRoute("AfterRegistration"));
            }
            catch (Exception e)
            {
                model.Error = e.Message;
                return(View(model));
            }
        }
Beispiel #23
0
        public async Task <ICollection <UserDTO> > Execute(int id, WebRequestHelper helper)
        {
            Query query = queryManager.Get(id);

            if (query == null)
            {
                return(null);
            }
            ICollection <UserDTO> users;
            HttpResponseMessage   httpResponseMessage = await httpClient.GetAsync(helper.CreateRequest(mapper.Map <QueryDisplayDTO>(query)));

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                users = await httpResponseMessage.Content.ReadAsAsync <ICollection <UserDTO> >();

                var entities = mapper.Map <IEnumerable <User> >(users);
                query = queryManager.SetExecuted(query);
                userManager.Add(query, entities.ToArray());
                return(users);
            }
            return(null);
        }
        public async Task <IActionResult> CreateUser([FromBody] UserModel userModel)
        {
            var addUser = new Users
            {
                Code        = "otomatik",
                Name        = userModel.Name,
                Lastname    = userModel.Lastname,
                UserName    = userModel.UserName,
                Password    = userModel.Password,
                UserGroupId = userModel.UserGroupId,
                EMail       = userModel.EMail,
                Enable      = true,
                Description = "açıklama"
            };

            var resultUser = await _userManager.Add(addUser);

            return(Ok(new
            {
                success = resultUser.Success,
                Message = resultUser.Message
            }));
        }
Beispiel #25
0
 public JsonResult GetOffer(User requestModel)
 {
     try
     {
         CResult <User> result = new CResult <User>();
         if (ModelState.IsValid)
         {
             result = _userManager.Add(requestModel);
             SigortamWcf.SigortamWcfClient sigortamWcfClient = new SigortamWcf.SigortamWcfClient();
             var CompanyOfferList = sigortamWcfClient.TeklifHesaplamaAsync(requestModel.StPlaka, requestModel.StTCKN, requestModel.StRuhsatSeriKodu, requestModel.StRuhsatSeriNo).Result;
             return(Json((object)new
             {
                 data = 0,
                 message = result.Desc,
                 success = result.Succeeded,
                 redirectUrl = "",
             }));
         }
         return(Json((object)new
         {
             data = 0,
             message = string.Join(";<br/> ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)),
             success = false,
             redirectUrl = "",
         }));
     }
     catch (Exception ex)
     {
         return(Json((object)new
         {
             data = 0,
             message = "Hata oluştu :" + ex.Message.ToString(),
             success = false,
         }));
     }
 }
Beispiel #26
0
 public async Task <ActionResult <User> > AddUser([FromBody] User user)
 {
     return(Ok(await _usersManager.Add(user)));
 }
Beispiel #27
0
 public HttpResponseMessage Add(User item)
 {
     _userManager.Add(item);
     return(new HttpResponseMessage(HttpStatusCode.OK));
 }
 public bool Add(User user, string password)
 {
     return(_userManager.Add(user, password));
 }
 public async Task <ApiResponse> Add([FromBody] UserDto param) => await userManager.Add(param);
        public ActionResult Register(User user)
        {
            _userService.Add(user);

            return(RedirectToAction("Index", "Product"));
        }