コード例 #1
0
        public HttpResponseMessage RoadZenAccountProviderRegistration(ProviderRegistrationRequest registrationRequest)
        {
            Services.Log.Info("New Account Provider Registration Request [API]");

            // Phone Number SS Validation
            if (!Regex.IsMatch(registrationRequest.Phone, "^[0-9]{10}$"))
            {
                Services.Log.Warn("Invalid phone number (must be 10 numeric digits");
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid phone number (must be 10 numeric digits");
            }
            if (!RegexUtilities.IsValidEmail(registrationRequest.Email))
            {
                Services.Log.Warn("Invalid e-mail address");
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid e-mail address");
            }

            // Get the logged-in user.
            var currentUser = this.User as ServiceUser;

            stranddContext context = new stranddContext();

            Account account = context.Accounts.Where(a => a.Phone == registrationRequest.Phone).SingleOrDefault();
            if (account != null)
            {
                string responseText = "Phone Number Already Registered";
                Services.Log.Warn(responseText);
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, WebConfigurationManager.AppSettings["RZ_MobileClientUserWarningPrefix"] + responseText);

            }

            //Password SS Validation
            if (registrationRequest.Password.Length < 6)
            {
                Services.Log.Warn("Invalid password (at least 6 chars required)");
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid password (at least 6 chars required)");
            }

            byte[] salt = RoadZenSecurityUtils.generateSalt();

            Guid guid = Guid.NewGuid();

            Account newUserAccount = new Account
            {
                Id = guid.ToString(),
                Name = registrationRequest.Name,
                Phone = registrationRequest.Phone,
                Email = registrationRequest.Email,
                ProviderUserID = "RoadZen:" + guid.ToString("N").ToUpper(),
                Salt =  salt,
                SaltedAndHashedPassword = RoadZenSecurityUtils.hash(registrationRequest.Password, salt)
            };

            context.Accounts.Add(newUserAccount);
            context.SaveChanges();

            Services.Log.Info("Account for [" + newUserAccount.ProviderUserID + "] has been created");
            return this.Request.CreateResponse(HttpStatusCode.Created, "Account for [" + newUserAccount.ProviderUserID + "] has been created");
        }
コード例 #2
0
        public AccountExcelData(Account baseAccount)
        {
            this.Id = baseAccount.Id;
            this.Phone = baseAccount.Phone;
            this.Name = baseAccount.Name;
            this.Email = baseAccount.Email;
            this.ProviderUserID = baseAccount.ProviderUserID;
            this.Salt = System.Convert.ToString( baseAccount.Salt);
            this.SaltedAndHashedPassword = System.Convert.ToString(baseAccount.SaltedAndHashedPassword);
            this.Version = System.Convert.ToString( baseAccount.Version);

            this.RegisterDate = (baseAccount.CreatedAt != null)  ? (DateTimeOffset) baseAccount.CreatedAt : DateTimeOffset.MinValue;
            this.UpdatedAt = (baseAccount.UpdatedAt != null) ? (DateTimeOffset)baseAccount.UpdatedAt : DateTimeOffset.MinValue;
            this.Deleted = System.Convert.ToString( baseAccount.Deleted);

            stranddContext context = new stranddContext();
            int SubmittedCount = context.Incidents.Count(u => u.ProviderUserID == baseAccount.ProviderUserID);

            this.IncidentSubmittedCount = System.Convert.ToString(SubmittedCount);
        }