コード例 #1
0
        public async Task <bool> UpdateUserPass(Data.Models.MainDB.User user, string newPassword)
        {
            byte[] passwordHash, passwordSalt;
            _utilities.CreatePasswordHash(newPassword, out passwordHash, out passwordSalt);

            //user.PasswordHash = passwordHash;
            //user.PasswordSalt = passwordSalt;

            _db.UserRepository.Update(user);

            return(await _db.SaveAsync());
        }
コード例 #2
0
        public async Task <bool> UpdateUserPass(Data.Models.MainDB.User user, string newPassword)
        {
            byte[] passwordHash, passwordSalt;
            _utilities.CreatePasswordHash(newPassword, out passwordHash, out passwordSalt);


            var token = await _userManager.GeneratePasswordResetTokenAsync(user);

            var result = await _userManager.ResetPasswordAsync(user, token, newPassword);


            //user.PasswordHash = passwordHash.ToString();

            //_db.UserRepository.Update(user);

            return(result.Succeeded);
        }
コード例 #3
0
        public async Task <Data.Models.MainDB.User> RegisterAsync(Data.Models.MainDB.User user, Photo photo, string password)
        {
            byte[] passwordHash, passwordSalt;
            _utilities.CreatePasswordHash(password, out passwordHash, out passwordSalt);

            //user.PasswordHash = passwordHash;
            //user.PasswordSalt = passwordSalt;

            await _db.UserRepository.InsertAsync(user);

            await _db.PhotoRepository.InsertAsync(photo);

            if (await _db.SaveAsync())
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public async Task <IActionResult> RegisterWithSocial(UserForRegisterWithSocialDto userForRegisterWithSocialDto)
        {
            var model = new ApiReturn <UserForDetailedDto>
            {
                Status = true
            };

            var user = await _db.UserRepository.GetByIdAsync(userForRegisterWithSocialDto.UserId);

            if (user != null)
            {
                var oldphoto = await _db.PhotoRepository.GetAsync(p => p.UserId == userForRegisterWithSocialDto.UserId && p.IsMain);

                oldphoto.Url = userForRegisterWithSocialDto.PhotoUrl;
                _db.PhotoRepository.Update(oldphoto);
                await _db.SaveAsync();

                model.Message = "ورود شما با موفقیت انجام شد";
                model.Result  = _mapper.Map <UserForDetailedDto>(user);
                model.Result.IsRegisterBefore = true;
                return(CreatedAtRoute("GetUser", new
                {
                    controller = "Users",
                    v = HttpContext.GetRequestedApiVersion().ToString(),
                    id = userForRegisterWithSocialDto.UserId
                }, model));
            }
            else
            {
                var userToCreate = new Data.Models.MainDB.User
                {
                    UserName             = userForRegisterWithSocialDto.Email,
                    Name                 = userForRegisterWithSocialDto.Name,
                    PhoneNumber          = "0000",
                    Address              = "",
                    City                 = "",
                    Gender               = true,
                    DateOfBirth          = DateTime.Now,
                    IsActive             = true,
                    Status               = true,
                    PhoneNumberConfirmed = true
                };
                userToCreate.Id = userForRegisterWithSocialDto.UserId;
                var photoToCreate = new Photo
                {
                    UserId      = userForRegisterWithSocialDto.UserId,
                    Url         = userForRegisterWithSocialDto.PhotoUrl,
                    Description = "Profile Pic",
                    Alt         = "Profile Pic",
                    IsMain      = true,
                    PublicId    = "2"
                };
                var notifyToCreate = new Notification
                {
                    UserId         = userForRegisterWithSocialDto.UserId,
                    EnterEmail     = true,
                    EnterSms       = false,
                    EnterTelegram  = true,
                    ExitEmail      = true,
                    ExitSms        = false,
                    ExitTelegram   = true,
                    LoginEmail     = true,
                    LoginSms       = false,
                    LoginTelegram  = true,
                    TicketEmail    = true,
                    TicketSms      = false,
                    TicketTelegram = true
                };
                var walletMain = new Wallet
                {
                    UserId      = userForRegisterWithSocialDto.UserId,
                    Name        = "اصلی ماد پی",
                    IsMain      = true,
                    IsSms       = false,
                    Inventory   = 0,
                    InterMoney  = 0,
                    ExitMoney   = 0,
                    OnExitMoney = 0
                };
                var walletSms = new Wallet
                {
                    UserId      = userForRegisterWithSocialDto.UserId,
                    Name        = "پیامک",
                    IsMain      = false,
                    IsSms       = true,
                    Inventory   = 0,
                    InterMoney  = 0,
                    ExitMoney   = 0,
                    OnExitMoney = 0
                };

                var result = await _userManager.CreateAsync(userToCreate, userForRegisterWithSocialDto.Email);

                if (result.Succeeded)
                {
                    await _authService.AddUserPreNeededAsync(photoToCreate, notifyToCreate, walletMain, walletSms);

                    var creaatedUser = await _userManager.FindByNameAsync(userToCreate.UserName);

                    await _userManager.AddToRolesAsync(creaatedUser, new[] { "User" });

                    var userForReturn = _mapper.Map <UserForDetailedDto>(userToCreate);
                    userForReturn.IsRegisterBefore = false;
                    _logger.LogInformation($"{userForRegisterWithSocialDto.Name} - {userForRegisterWithSocialDto.Email} ثبت نام کرده است");
                    //
                    model.Message = "ورود شما با موفقیت انجام شد";
                    model.Result  = userForReturn;
                    return(CreatedAtRoute("GetUser", new
                    {
                        controller = "Users",
                        v = HttpContext.GetRequestedApiVersion().ToString(),
                        id = userToCreate.Id
                    }, model));
                }
                else if (result.Errors.Any())
                {
                    _logger.LogWarning(result.Errors.First().Description);
                    //
                    errorModel.Message = result.Errors.First().Description;
                    return(BadRequest(errorModel));
                }
                else
                {
                    errorModel.Message = "خطای نامشخص";
                    return(BadRequest(errorModel));
                }
            }
        }
コード例 #5
0
        public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto)
        {
            var model = new ApiReturn <UserForDetailedDto>
            {
                Status = true
            };

            userForRegisterDto.UserName = userForRegisterDto.UserName.ToMobile();
            if (userForRegisterDto.UserName == null)
            {
                model.Status  = false;
                model.Message = "شماره موبایل صحیح نمیباشد مثال : 09121234567";
                return(BadRequest(model));
            }
            var OtpId = userForRegisterDto.UserName + "-OTP";
            //
            var code = await _db.VerificationCodeRepository.GetByIdAsync(OtpId);

            if (code == null)
            {
                errorModel.Message = "کد فعالسازی صحیح نمباشد اقدام به ارسال دوباره ی کد بکنید";
                return(BadRequest(errorModel));
            }
            if (code.ExpirationDate < DateTime.Now)
            {
                _db.VerificationCodeRepository.Delete(OtpId);
                await _db.SaveAsync();

                errorModel.Message = "کد فعالسازی منقضی شده است اقدام به ارسال دوباره ی کد بکنید";
                return(BadRequest(errorModel));
            }
            if (code.Code == userForRegisterDto.Code)
            {
                var userToCreate = new Data.Models.MainDB.User
                {
                    UserName             = userForRegisterDto.UserName,
                    Name                 = userForRegisterDto.Name,
                    PhoneNumber          = userForRegisterDto.UserName,
                    Address              = "",
                    City                 = "",
                    Gender               = true,
                    DateOfBirth          = DateTime.Now,
                    IsActive             = true,
                    Status               = true,
                    PhoneNumberConfirmed = true
                };
                var photoToCreate = new Photo
                {
                    UserId = userToCreate.Id,
                    Url    = string.Format("{0}://{1}{2}/{3}",
                                           Request.Scheme,
                                           Request.Host.Value ?? "",
                                           Request.PathBase.Value ?? "",
                                           "wwwroot/Files/Pic/profilepic.png"), //"https://res.cloudinary.com/keyone2693/image/upload/v1561717720/768px-Circle-icons-profile.svg.png",
                    Description = "Profile Pic",
                    Alt         = "Profile Pic",
                    IsMain      = true,
                    PublicId    = "0"
                };
                var notifyToCreate = new Notification
                {
                    UserId         = userToCreate.Id,
                    EnterEmail     = true,
                    EnterSms       = false,
                    EnterTelegram  = true,
                    ExitEmail      = true,
                    ExitSms        = false,
                    ExitTelegram   = true,
                    LoginEmail     = true,
                    LoginSms       = false,
                    LoginTelegram  = true,
                    TicketEmail    = true,
                    TicketSms      = false,
                    TicketTelegram = true
                };
                var walletMain = new Wallet
                {
                    UserId      = userToCreate.Id,
                    Name        = "اصلی ماد پی",
                    IsMain      = true,
                    IsSms       = false,
                    Inventory   = 0,
                    InterMoney  = 0,
                    ExitMoney   = 0,
                    OnExitMoney = 0
                };
                var walletSms = new Wallet
                {
                    UserId      = userToCreate.Id,
                    Name        = "پیامک",
                    IsMain      = false,
                    IsSms       = true,
                    Inventory   = 0,
                    InterMoney  = 0,
                    ExitMoney   = 0,
                    OnExitMoney = 0
                };

                var result = await _userManager.CreateAsync(userToCreate, userForRegisterDto.Password);

                if (result.Succeeded)
                {
                    await _authService.AddUserPreNeededAsync(photoToCreate, notifyToCreate, walletMain, walletSms);

                    var creaatedUser = await _userManager.FindByNameAsync(userToCreate.UserName);

                    await _userManager.AddToRolesAsync(creaatedUser, new[] { "User" });

                    var userForReturn = _mapper.Map <UserForDetailedDto>(userToCreate);

                    _logger.LogInformation($"{userForRegisterDto.Name} - {userForRegisterDto.UserName} ثبت نام کرده است");
                    //
                    model.Message = "ثبت نام شما با موفقیت انجام شد";
                    model.Result  = userForReturn;
                    return(CreatedAtRoute("GetUser", new
                    {
                        controller = "Users",
                        v = HttpContext.GetRequestedApiVersion().ToString(),
                        id = userToCreate.Id
                    }, model));
                }
                else if (result.Errors.Any())
                {
                    _logger.LogWarning(result.Errors.First().Description);
                    //
                    errorModel.Message = result.Errors.First().Description;
                    return(BadRequest(errorModel));
                }
                else
                {
                    errorModel.Message = "خطای نامشخص";
                    return(BadRequest(errorModel));
                }
            }
            else
            {
                errorModel.Message = "کد فعالسازی صحیح نمباشد اقدام به ارسال دوباره ی کد بکنید";
                return(BadRequest(errorModel));
            }
        }