Ejemplo n.º 1
0
        public ActionResult Index(OSUser osUser, string password)
        {
            try
            {
                osUser.LastUpdate = DateTime.Now;
                osUser.IsActive   = true;
                osUser.ImageFile  = "70x70.jpg";

                ViewBag.Success = true;

                // اختصاص کد کاربر
                osUser.Id = Guid.NewGuid().ToString();

                // اختصاص نقش Public به کاربر
                osUser.Roles.Add(new IdentityUserRole()
                {
                    RoleId = StaticValues.PublicRoleID, UserId = osUser.Id
                });

                // ایجاد کاربر
                var result = UserManager.Create(osUser, password);

                if (result.Succeeded)
                {
                    UserNotifications.Send(StaticValues.AdminID, String.Format("ثبت نام کاربر '{0}'", osUser.UserName), "/Admin/OSUsers/Edit/" + osUser.Id, NotificationType.Success);

                    if (!String.IsNullOrWhiteSpace(osUser.Mobile))
                    {
                        SMSServices.Register(osUser.Firstname,
                                             osUser.Lastname,
                                             osUser.UserName,
                                             password,
                                             osUser.Mobile,
                                             osUser.Id);
                    }

                    EmailServices.Register(osUser.Firstname,
                                           osUser.Lastname,
                                           osUser.UserName,
                                           password,
                                           osUser.Email,
                                           osUser.Id);
                }
                else
                {
                    throw new Exception(result.Errors.Aggregate((a, b) => a + ", " + b));
                }
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(View(url + "Index.cshtml"));
        }
Ejemplo n.º 2
0
        private IdentityResult registerUser(ref OSUser osUser)
        {
            if (UserManager.FindByEmail(osUser.Email) == null)
            {
                osUser.UserName   = osUser.Email;
                osUser.LastUpdate = DateTime.Now;
                osUser.IsActive   = true;

                // اختصاص کد کاربر
                osUser.Id = Guid.NewGuid().ToString();

                // اختصاص نقش Public به کاربر
                osUser.Roles.Add(new IdentityUserRole()
                {
                    RoleId = StaticValues.PublicRoleID, UserId = osUser.Id
                });

                // ایجاد کاربر
                var password = new Random().Next(100000, 999999).ToString();
                var result   = UserManager.Create(osUser, password);

                if (!String.IsNullOrWhiteSpace(osUser.Mobile))
                {
                    SMSServices.Register(osUser.Firstname,
                                         osUser.Lastname,
                                         osUser.UserName,
                                         password,
                                         osUser.Mobile,
                                         osUser.Id);
                }

                EmailServices.Register(osUser.Firstname,
                                       osUser.Lastname,
                                       osUser.UserName,
                                       password,
                                       osUser.Email,
                                       osUser.Id);

                return(result);
            }
            else
            {
                osUser = UserManager.FindByEmail(osUser.Email);

                return(IdentityResult.Success);
            }
        }